- Home /
How to kill enemies by jumping on their heads?
I'm making a 2d platformer, and I can't seem to figure out how to make it so that if i jump on an enemies head it will die.
It it totally dependent on how you have written your scripts and constructed your gameObjects. Are you using a character controller ? if so (pseudocode):
function OnControllerColliderHit( hit : ControllerColliderHit )
{
if ( !isGrounded )
{
if ( hit.collider.gameObject.name == "Enemy" )
{
// enemy said "ouch, you jumped and landed on me"
}
}
}
This is probably the most detail you are going to get without providing any information about your project and setup.
Watch this, then edit your question : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
Answer by tastygraphgames · Mar 09, 2013 at 03:23 PM
a simple approach would be to compare your player's Y position to the enemy's Y position.(assuming you're using Y as the Vertical/Up-Down axis where the higher Y is physically above the lower Y position)
So if your player has a higher Y position value vs the enemy's Y value + Enemy's own Height. Then your player must be above your enemy and should be kill the enemy and not take damage himself.
Your answer
Follow this Question
Related Questions
Making a Game like 'Kitty Cannon'? 1 Answer
2d games advice 4 Answers
animation 2d platformer 2 Answers
jittery jumping 2D character 0 Answers
Box not jumping, just jitters like it's stuck to the ground (2D platformer movement) 1 Answer