0 votes

I'm making a 2D platformer with an enemy that moves left and right.

It already changes direction when facing a wall, but I would like it to change directions when it's about to fall off from a platform by checking the area near and below it.

Something like this: https://ibb.co/QXGH6Pv

Godot version 3.2.3
in Engine by (12 points)

You can use the test_move() function to detect the spaces in front and the back of an enemy.

1 Answer

0 votes

You could have a raycast in front of the kinematic body checking if there is a floor where it is moving towards.

by (254 points)

I tried, but the enemy has a wide capsule collision shape.

You can use the raycast's add_exception method for all your enemies.

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 Frequently asked questions and 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.