- Home /
Jump on Enemy heads to destroy enemy?
I have a little problem with collision. I made a script to destroy enemies on collision, and when I collide with the enemy by moving forward, it is destroyed. But when jump on the head of the enemy, it does not destroy, but rather, my player will be on the head of the enemy.
Is there a way for me to destroy enemies by jumping on their heads? Something just like Super Mario Bros where Mario can jump on enemies and they are destroyed but when he collides with an enemy, he loses health or a life.
Some Code would help also, the answer below is assu$$anonymous$$g ontrigger I would assume oncollider function.
Using a Sphere Collider with "Is Trigger" and attaching a script to it using the OnTriggerEnter() function is the most effective and simple way. Example:
var EnemyGO : GameObject;
function OnTriggerEnter (other : Collider){
//add any other actions here like adding player points and so on.
yield WaitForSeconds(1);
Die();
}
function Die (){
Destroy(EnemyGO);
}
Simple is better.
Answer by EION Technology · May 12, 2013 at 12:18 AM
Yes. It is actually very easy. I assume that you already are using a "Is Trigger" collider, and using an OnTriggerEnter() function on a script. All you have to do for them to die when jumping on their heads is to have the "Is Trigger" SphereCollider located at the head of your enemy, not the whole body like you have now.
Your answer
Follow this Question
Related Questions
Scripts Destroys all Objects its Attached to! 2 Answers
c# array of game objects movement help 1 Answer
Enemy Approaching player and then stopping in front?? 1 Answer
My movement function with jump won't work with collider function 1 Answer
Why does this script make my camera jump when I move back? 1 Answer