- Home /
What's wrong with my code? (Collision, JS)
In my FPS you have like a plataform and if you fall from it you're supposed to die when you hit the ground, so i made a box with a collider (removed mesh renderer and added "FallDead" tag) then i called this is my CharacterLife script (inside the Player GameObject):
function OnCollisionEnter (collision : Collision){
if(collision.gameObject.tag == "Enemy"){
totalHealth = totalHealth - 10;
}
if(collision.gameObject.tag == "FallDead"){
totalHealth = 0;
}
}
When i collide with my enemy (with the tag "Enemy") my player loses 10 health, and this part works perfect, but the second one, checking if the player hits the ground, is not working.
The player has no Rigidbody but the Ground game object has (with freezed rotation and position, and no gravity) and I CAN'T add a rigidbody to my player, i tried that once and the physics went crazy everything started flying and stuff like that...
Also I apologize about my english i'm not american.
Well, if the first part works perfectly but the second part does not, that rather suggests that your ground is not tagged with the "FallDead" tag...
Answer by flapy-monkey · Dec 23, 2014 at 05:05 PM
I think triggle collider enough, you can try it. and maybe you can check here
found how to reach this screen, and $$anonymous$$e is exactly like yours
Answer by xwheat32x · Dec 23, 2014 at 05:02 PM
Under the script "(shape) Collider" on your trigger collider, you will see a check box called "Is Trigger". Check that box.
That would stop OnCollisionEnter being called completely....
Your answer
Follow this Question
Related Questions
OnCollisionEnter Push Object Problem 0 Answers
Unity 2D Colliders not Colliding 2 Answers
Disable a diffrent collision 1 Answer
Collision with renderer.enabled? 0 Answers
Sound on collision 3 Answers