0 votes

I want my enemy to go back and forth on any sized platform without falling off the side

in Engine by (395 points)

3 Answers

0 votes

That is not pathfinding, is just "border check".

Add raycasts to the sides pointing down, if going to the left, check the left one, if going to the right, check the right one.

If the raycast gives a "false" collision with the floor, is because there is no floor and the body need to turn to the other side.

The platformer demo uses that simple approach for the enemies.

by (7,888 points)
0 votes

you can use the Test_motion function in the Rigidbody, just check if the enemy will collide in a position that is equal to his width(of the collision box/ sprite, what works best for you) and 1 to his height - 1 down( aka the vector should be (Width , Height - 1) to the direction he is going, that way, if it returns false you know that there is no ground there...

you can tweak the numbers, add or subtract some numbers or variables like speed to match your needs

by (1,196 points)
0 votes

You can use a "marker" to make the enemy go in the other direction. Look at Dolphin Island 2 project and you'll see how they did it.
Dolphin Island 2 - Godot project - GitHub

by (22 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.