Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Collider stopped working when tilemap collider is switched to composite collider

Discussion in '2D' started by thomasbui198, May 8, 2021.

  1. thomasbui198

    thomasbui198

    Joined:
    May 7, 2021
    Posts:
    1
    Hello,

    ISSUE: Tank (composite collider) and projectile (circular collider) can collide with a standard tilemap collider. However, after changing the tilemap to use composite collider, the projectile still collide but the tank stopped colliding.

    DETAILS:
    I have a top down 2D game that's made up of a tilemap and a player (tank) that can shoot out projectiles.

    If I move the tank or shoot the projectile, collision is detected fine and physics is working properly.

    upload_2021-5-7_17-1-18.png

    I want to make the tilemaps to use the composite collider since the tank's projectile was bouncing weirdly at the corners of the tiles. Here's what I did after looking at tutorials:
    upload_2021-5-7_16-54-19.png


    The result is the projectile bounces with no issue (yay) but the tank now goes through the walls.
    upload_2021-5-7_17-3-50.png

    Tank Details:
    - Composite collider with two rectangular collider (one for the hull and one for the barrel)
    - Rigidbody 2D: Dynamic, freeze z-axis rotation
    - Movement code:

    Code (CSharp):
    1. Vector2 distance = -rigidBody.transform.right * movementSpeed * Time.fixedDeltaTime;
    2.         rigidBody.MovePosition((Vector2)rigidBody.transform.position + distance);

    - Rotation code:

    Code (CSharp):
    1. rigidBody.transform.RotateAround(hullRenderer.bounds.center, Vector3.back, rotationSpeed);

    Projectile Details:
    - Circular Collider
    - Rigidbody 2D: Dynamic, use a material that gives it bounciness of 1 and friction of 0
    - Movement Code:

    Code (CSharp):
    1. gameObject.GetComponent<Rigidbody2D>().velocity = direction * speedData.value;

    I'm very confused on why this is happening. Any help would be appreciated.
     

    Attached Files: