0 votes

A lot of platformers have enemies that travel in a circle around a small platform, clinging to the platform all the way around. Like a little spider that crawls around the circumference of a platform.

This is a 2D platformer game with a lot of movement done using move-and-slide, but also some enemies that follow unique Path2D nodes, but I don't want to have to make a Path2D for this enemy.

Is there a built-in way to figure out how/when to move the enemy? In a best-case scenario, you'd be able to place an enemy on a random platform and they would happily crawl over it.

in Engine by (179 points)

1 Answer

0 votes
Best answer

So I think the easiest way would be to have a raycast at the enemy thats slightly rotated,
so you can check if the platform end in front of the enemy or if its still there. If the raycast doesn't hit anything, just make the enemy walk into the other direction, and if the raycast touches the platform, make it walk straight forward.

by (320 points)
selected by

I think that makes sense. A diagonal raycast into the wall in the direction the enemy is moving in, with the direction vector rotating a degree inwards for every frame the raycast isn't touching the block.

Things could get more complicated if the block is more like a wall, and the spark would have to turn away from the wall or else run into it. My guess is a raycast could fix that too though. I'll stick with the simple version for this first part though. Thanks!

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 [email protected] with your username.