- Home /
Collision vs trigger
Hello everyone.
Trying to learn Collision, but I'm stuck at this 2D collision.
Why is trigger working but not OnCollisionEnter2D ? This is only if I have actived "Is Trigger"
Both game objects have a collision box.
function OnCollisionEnter2D (hit:Collision2D){
if(hit.collider.tag == "Ground"){
Destroy (gameObject);
}
}
/*
function OnTriggerEnter(hit:Collider){
if(hit.tag != "Ground"){
Destroy (gameObject);
}
} */
Does at least one of the colliding GameObjects have a Rigidbody?
I tried to add it earlier just for a test, and it says it already has box collider. I'm testing this on the ground and the player at this moment, they are working pretty well together (collision - $$anonymous$$ovement etc). Just not able to use the function somehow.
Do you have a 2d collider? weird that in a 2d game the OnTriggerEnter works and OnCollisionEnter2D doesn't... it seems like you are using 3d colliders from your description
ofc it is, you should use box 2d collider and for the capsule, 2 2d sphere colliders with a box collider in the middle, if it's for a character, you use only a sphere collider for the bottom and a box collider for the body, all 2d colliders though!
Answer by MadJohny · Apr 27, 2014 at 03:26 PM
if you are want it to use that way you can, you will have to program the game like if it was a 3d game though, which isn't that bad. But to be honest, I think the 2d toolset is more powerful and optimized than the original one (3d). I recommend you taking a look at the tutorials on the unity website, they have a tutorial series dedicated to the 2d toolset I think. I would convert it to 2d since it's more powerful and seems to be better overall, but if you want to keep it the way it is atm, it's your choiche.
Your answer
Follow this Question
Related Questions
Trouble Descaling 2D object 1 Answer
Find the highest point of a stack of gameobjects 2 Answers
Why my triggers don't collide? 2D 0 Answers
Collision with renderer.enabled? 0 Answers
Check if a Collider2D is hit by a Trigger Collider2D 1 Answer