Having great difficulty w/ collisions, rigidbodies
Hello,
I am making a 2D game, and the collision detection is not working at all. I am aware that one of the objects must be a Rigidbody (preferably the moving one) in order for a collision to be detected, which I have done already. I set the walls to be triggered by an Edge Collider 2D. This is my code for my trigger detection class:
public class BoundaryWall : MonoBehaviour {
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log(other.name + " entered the trigger");
}
void OnTriggerExit2D(Collider2D other)
{
Debug.Log(other.name + " exited the trigger");
}
}
The program does not even acknowledge that the character stepped over the triggers. I do not know how to detect collisions when the objects are supposed to move freely. Should I use RigidBody2D or RigidBody?
Firstly, you want rigidbody2D; rigidbody2D uses 2D physics events (which is what your wall is also using), regular rigidbodies use 3D physics events
Secondly, make sure collisions between your moving object's layer and your wall's layer are enabled in your project's 2D physics settings (this should default to enabled, so it's unlikely to be disabled if you haven't fiddled with this)
Thirdly, make sure your wall's 2D collider has IsTrigger enabled
Thanks for the advice. I am well on my way to having functional walls.
Answer by RavenHardt · Feb 11, 2018 at 12:07 AM
If right now you are using RigidBody2D then, please make sure you have body type set to Dynamic. If you do not want gravity then turn the gravity scale all the way down to zero. if you have done this and it still doesn't work please reply quickly.
Your answer
![](https://koobas.hobune.stream/wayback/20220612152350im_/https://answers.unity.com/themes/thub/images/avi.jpg)