Jumping on an enemy's head

If we think of the Mario games, Mario usually takes damage if he touches an enemy, except if he lands on top of them, then Mario is fine and the enemy is damaged.

I was thinking that to accomplish this, I would do raycasts checking below the player’s feet to register contact with the enemy. I would also check that the player is in the state of falling. And I see that ray_cast_response gives us a position, which is the world position of the hit.

My question is how can I tell if that hit position is above the upper y boundary of the enemy object? This way it would only hurt the enemy if you were actually on top of them, and not, for example, crashing down and hitting them in the side.

Check if the normal is orthogonal to the ground.

2 Likes

You can add kinematic collision body on the head of enemy and on the foot of player, then check the collisions.

1 Like

Thank you both for those great ideas! After some testing I think I am going to use the method of checking the normal, just so I don’t have to set up the additional colliders on each enemy.

1 Like