Hello Guest

Author Topic: strange collision behavior  (Read 5187 times)

jtuttle

  • Newbie
  • *
  • Posts: 4
    • View Profile
strange collision behavior
« on: September 16, 2013, 05:32:55 am »
Hi there. I've read a few of other posts about collision detection on this forum but none of them seem to address my issue. I'm making a 2D tile-based RPG/hack and slash (like the original Zelda) and I'm currently trying to simple get my player sprite to collide with certain wall sprites in the map tile sheet. My camera and both spritesheets are set up to use 20 px/meter (because I remember reading that setting works okay with Unity's physics). I've attached colliders and rigidbodies to both the player and the tile. Both the player and tile have their rigidbody rotations and z-position locked. The tile also has its x and y position locked. Gravity and kinematic are both unchecked on the rigidbody (though I've tried messing with both).

To move the player gameobject, I set its rigidbody velocity based on keyboard/controller input. When the player touches the tile, I can get the OnEnter event to fire no problem and the wall collision sometimes works, but it's not reliable. I found that it usually works if I approach the tile from a compass direction, but if I approach the wall tile from the diagonal, the player gameobject will often just slip right inside the tile's collider, even if it's much bigger than the player's.

Am I doing something wrong here? Is this not how collision is supposed to be set up with 2D Toolkit? Any tips? Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: strange collision behavior
« Reply #1 on: September 16, 2013, 11:02:08 am »
This isn't really about how you should set up collisions with 2D Toolkit, but rather about how collisions in Unity work. Firstly, you should probably make the depth of the wall colliders a lot higher. Also, consider using a character controller. It tends to play a lot better as a character controller - it will slide along walls and stuff.

Check this for an example of a top down character controller.
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,2476.0.msg12395.html#msg12395

jtuttle

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: strange collision behavior
« Reply #2 on: September 17, 2013, 04:27:02 am »
Setting the depth higher helped a lot, thanks. My only hesitation about using character controller is that I will probably want the player to be a physical object at some point. Maybe it'll work nicely for now though. Appreciate the advice!