Enemy movement on a set path

Ik everyone has trouble with enemy movement going left to right and stuff but how do you make an enemy with no gravity follow a set path? Oh and to make things harder (for me) im releasing this game so cant share the link.

A set path?

You could do that with raycasts and switches.

say you started a path going right, have always going into switches, have racy casts turn them on, all connected to a velocity.

Or you could substitute the ray-casts for proximity’s, collisions, or timers.

thanks :slight_smile: any way you could show me how exactly? im new to raycasts

Here’s a various enemy example by PixelPizza. Just in the editor and look through all of the levels. I’m pretty sure most of the moving enemies use raycasts.


I know you can also do it by collisions, when it hits a block, then it turns… this is also what we did on dark defence.

1 Like

also this may be a stupid question but how do u stop?

like stop the enemy moving

For the enemy, I’d say this:

Trigger (whether it being raycast = miss, or something else) ==> get number behavior 0 ==> X velocity

That would set the velocity to zero. Remember to have it reset to the normal values so that it cab start moving again when detecting a player object.

Let me know if you have any questions:)

1 Like

also could you please give me an example? im still a little confused. thanks @rcreger

1 Like

Here, I made a quick one for ya’, sprites and all:)

Crisp Movement Example

It’s not used on an enemy, but it would work the same way. Check the player bundle labeled “Run & Jump”, it’s modified.

1 Like

also is there a way to make the enemy move a certain amount of pixels then stop? woulld i have to use the position block?

1 Like

I think so. I’m pretty sure you’d have to connect the number in the X+ input, though, and it’d probably just shoot to that position instead of slowly move to it. Perhaps having a timer instead that makes the object flip when needed? It would give the same, but smoother result. Just know that if the player throws off the enemy’s path, it will still continue doing the same thing but in a different spot - no matter how big or small the area is.

ok thankyou! subject now officially closed.