2d collision detection not working
I'm not sure what I'm doing wrong here. Theres a prefab of a wall. it spawn randomly and falls down. The player has to dodge it. Heres the code:
function OnCollisionEnter(col : Collision) {
print("collision");
}
(Attached to the player)
I've tried many combinations of each having box collider and rigid body components. Nothing seems to work. Which objects need which components or is there something wrong with the code? I've also tried doing OnTriggerCollision with no results either.
Answer by TBruce · Dec 26, 2016 at 07:07 PM
This is because you are using the 3D version of collision. For 2D you need to change, like so
function OnCollisionEnter2D (col : Collision2D)
{
print("collision");
}
Your answer
Follow this Question
Related Questions
Object Colliding while passing along another object . 0 Answers
OnCollisionEnter2D not calling, but objects are colliding. 1 Answer
Projectile colliding with player at origin,Excluding a specific game object 0 Answers
Detect whether a Rigidbody collided with a Trigger 2 Answers
Projectile colliding with player at origin,Excluding a specific game object 0 Answers