- Home /
Issue with Collision (Probably an easy fix)
While working on collisions in my Unity game, I have run into a problem. No matter how I seem t change this code, my game is not registering a collision. As far as I am aware, the Unity function OnCollisionEnter(); requires the following (All of which I have) -A rigidbody -A collider (Any type, for example a box collider) -The object have isKinematic to be false
Any ideas? My code is below.
function OnCollisionEnter(other : Collision) { if(other.gameObject.tag === "Zombie") { print("Collsion Detected"); //Real Code to be added later (Just a test) } }
Your code looks fine. First, both objects must have a collider, and neither collider should have 'isTrigger' set. Next at the top of the function above add:
Debug.Log(other.collision.tag+", "+other.collision.name);
This will tell you if the collision is happening, and if so, the name and tag of the game object that is colliding.
I tried the above code, and it does not log anything for me. Yet I have the setup correct as far as I am aware. Neither of are $$anonymous$$inematic or a trigger, they are both rigidbodies, and they are all a collider (The player is a capsule collider, and the zombie/enemy is a Capsule Collider as well).
Try removing one of the equal signs. You should only do a double == when doing a compare.
Still nothing. I think the issue is in the actual detection of the collision. If the code looks fine, it must be an error in the way I have the components set up? Any ideas?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Analysing player metrics help 0 Answers
Check if an object is at a relative position? 2 Answers
Damage on collision problems... 0 Answers
HELP PLEASE! 3 Answers