(Solved) Random Enemy Movement with Timer.....Enemies stopping?

I have enemies on screen which I want to have move in a direction using forces, then every 3 seconds, I want them to randomly change direction seamlessly without stopping. I set up an object variable “Direction” for the enemy in which 1=Up, 2=Down, 3=Left, and 4=Right. Well, here is the code I’m using:

The problem I’m having is that the enemies seem to randomly stop moving at times, just sitting still with their animation still playing. I want the enemies only able to move up, down, left, and right, and for that direction to change every 3 seconds without them stopping in between direction changes or otherwise.

Does anyone have any idea why the enemies seem to be stopping in place at unexpected times, seemingly at random? Let me know what I might need to change in my code. Thanks in advance!

Hi,
You might need touse a “For Each” type of event. I think the second event is stopping every enemy even though only one of their timers is triggered

2 Likes

If you use RandomWithStep(), You can assign the direction directly without using the bottom half.

RandomWithStep(minimum number, maximum number, step)
(The result is a random number, either 0, 90, 180 or 270)

I tested it. It seems to work without the for each object but it’s not always easy to tell. So, it might be safer with it.

Either the previous one or this one.

1 Like

Thank you Keith (as usual!) and reina. I think I figured out the solution. I had the event for the timer being greater than 3 seconds ahead of the one for it being less than 3 seconds in the event sheet. It was reading them in the reverse order of how it should be. I moved the event for greater than 3 seconds to the bottom (under the sub-events for the movement directions), and everything is working as intended.

Man, permanent forces are really tricky sometimes! Thanks again to both of you!

1 Like