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

2D Box Colliders and Tile based map

Discussion in 'Editor & General Support' started by Kaestlyn, Apr 21, 2014.

  1. Kaestlyn

    Kaestlyn

    Joined:
    Apr 8, 2014
    Posts:
    3
    I am working on putting together a game that has character movement similar to some SNES RPGs. I'm a bit new to unity (came from XNA) and trying to setup my collisions right. The main problem I'm having is the following scenario:

    I have each tile take up a 1x1 square in unity. I have a case where I need to be able to move the player thru a single tile gap. I have a 2d box collider on the walls of the 1 tile gap and a box collider on the player as well. When the player attempts to move into the gap they are stopped.

    $Capture.PNG

    Is my only option to use a Circle collider on the player so they can "slide" thru the gap? If so, how can i prevent the slight slow down that occurs when the hit the gap with the circle collider?

    Thanks!
    Kaestlyn
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    using velocity directly as opposed to forces will prevent the slowdown.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I wouldn't bother with collisions for this sort of thing; they just make it harder and more complicated. What I did with SpriteTile is have the option to have "collisions" that don't use the physics engine at all (instead there is essentially an array that represents the world), which you can see an example of here.

    --Eric
     
  4. Kaestlyn

    Kaestlyn

    Joined:
    Apr 8, 2014
    Posts:
    3
    Thanks! I changed to just use velocity and now it seems to be ok. (I had to create a "No Friction" material to assign to the Box Colliders on the walls). I'm guessing a Circle Collider is my only option since the Box Colliders collide if I try to move the player into the 1 tile gap?
     
  5. Kaestlyn

    Kaestlyn

    Joined:
    Apr 8, 2014
    Posts:
    3
    I will definitely take a look at this. Right now I am just experimenting with Unity so trying to understand the various concepts and how to implement, so I'd like to avoid spending money currently. I will keep it in mind though in the future as this could be a very good option.