0 votes

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?

in Engine by (12 points)

1 Answer

0 votes

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, isonfloor() in a kinematic or rigid body will return true if the body is standing on a static floor and you are using moveandslide for your collision, but i don't think it will work well for objects on objects.

by (241 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.