# 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.
Thanks
Beaniesbugs
(beaniesbugs.com)

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 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.

https://flowlab.io/game/play/1572547

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.