Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Tile collider not working with rigid body 2d

Discussion in 'Physics' started by d0do, Aug 22, 2019.

  1. d0do

    d0do

    Joined:
    Feb 3, 2019
    Posts:
    5
    My top down 2d game uses walls made from tiles and i put a tile collider on them and a rigid body on my player but my player goes through the walls anyway
     
  2. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    130
    Your player also needs a Box Collider 2D.
     
  3. d0do

    d0do

    Joined:
    Feb 3, 2019
    Posts:
    5
    but how do i make it so the player moves as if it is top down (move up left right and down) freely without gravity. I turned gravity to 0 on the rigid body 2d but the player glithes when hitting the walls (tilemap collider)
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,960
    Can you try to be more precise on your explanation as it makes it much easier to help you.

    What has "glithes when hitting the walls" got to do with gravity? If presume you've either set gravity-scale on the Rigidbody2D to 0 in which case it'll have no gravity and that has nothing to do with collision detection. If your whole game is top-down then go to "Project Settings > Physics 2D" and set gravity to (0,0) then you don't need to modify any Rigidbody2D.

    When you say "glithes" I can only presume you force the body/collider over the "wall" then the physics system solves the overlap. This is often caused by modifying the Transform directly which is overriding the whole reason to add a Rigidbody2D which is to control the Transform. You should be using Rigidbody2D.MovePosition, or set the Rigidbody2D velocity or add a force to it.

    If none of this sounds like it'll solve the problem then perhaps you can post your player movement/collisions-detection code so we can help further.