- Home /
Fall Damage OnCollisionEnter Script Help.
Ok so a very good person in the community helped me with an issue i had about falling damage and gave me the script you can see below. The thing is it doesn't seem to work. I used a rigidbody for one of the colliders since this is an OnCollisionEnter but still nothing. The scene i am working right now has the first person controller on a cube up in the air and i want him to take damage as soon as he hits the ground. For some reason the Plane is use for the floor won't take the rigidbody and the test cube i used as my floor won't work with the script. Any help?
Here is the script:
function OnCollisionEnter(hit : Collision){
if(hit.gameObject.tag == ("Floor"))
Debug.Log("Take Damage");
}
Of course, the player won't be up in the air all the time. He will be able to walk on the floor too so is it possible to not be confused by this?
I'm afraid i can't do that. I get the usual error $$anonymous$$ identifier. We always have to use brackets :)
You can't just make up a tag in script. It has to already exist in the project settings and your floor has to be tagged it.
Also check the collision table near the bottom of http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
Of course i have created the tag before testing it!
Answer by dendens2 · Apr 20, 2013 at 02:39 PM
if(hit.gameObject.tag == ("Floor"))
Debug.Log("Take Damage");
What you did wrong is that the gameObject does not store the collision (At least that is what I think, lol). It is the collider. I think it should be this.
if(hit.collider.tag == ("Floor"))
Debug.Log("Take Damage");
I am pretty sure you can remove the brackets too.
Your answer
Follow this Question
Related Questions
How do I "remove/disable" collision? 3 Answers
Raycast to Terrain (Conditional Statements) 1 Answer
Collision not working 1 Answer
Detecting Collision points of particles? 1 Answer
Check if layers can collide 1 Answer