- Home /
Collision for a 2d Top Down RPG using 2d Toolkit
Hello,
I am in the process of moving to Unity from my own custom XNA engine. I am a bit confused about the built in collision handling. What is the best way to use this with a character controller on a top down 2d JRPG?
I did some simple tests and the collisions seem to work at times... other times I get strange results or the sprite even disappears from the map altogether. Just wondering what the best way to handle this is. Should I write my own handler from scratch?
Answer by Peter G · Aug 03, 2013 at 11:53 PM
Collisions should work just fine. The only thing I would recommend would be giving your sprite colliders real depth (even if the sprites don't have any) . If the colliders are too thin your character could pass through them, or walk over them.
Without knowing a little more about your set up its hard to know what's going wrong. Do the colliders have rigidbodys? Did you use Controller.Move()
Hi Peter,
I just checked and I noticed that when I move against a collision, the player sprite begins moving away into the z-direction until he goes out of view. How can I use Controller.$$anonymous$$ove() so he will never push away from the collision into the z-direction? X and Y would be fine.
The easiest way is just to reset the objects z-position every frame.
function Update () {
transform.position.z= 0
}
Or whatever height the character is at.
Thanks Peter, found that elsewhere, seems to work. The only thing I'm confused about now is when I collide with a tile on the map, and I keep holding the arrow key in that direction it slowly keeps moving in that direction, into the collision. Any idea why that would happen?
Never$$anonymous$$d got it - had to change the collider depth in my spritesheet within 2d T$$anonymous$$