Is there an engine function to tell if an object is ontop of another?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Krystal

I’m working on a platformer project and I’m looking to have enemies that can be killed by jumping on top of them. Is there an engine function that can tell if an object is on top of it?

:bust_in_silhouette: Reply From: lincolnpepper

simply use a collisionshape2D and link the overlapping event to the player script, then compare the object’s Y position relative to the player’s, and make sure the player’s Y velocity is positive. For good measure, you could add an extra collision shape on the enemy that only detects collision for the top part. To answer your question directly, is_on_floor() in a kinematic or rigid body will return true if the body is standing on a static floor and you are using move_and_slide for your collision, but i don’t think it will work well for objects on objects.