Enemy move

I’m trying to make the enemy move at a direction every few seconds, i have searched the forums but no luck so far and i sure there is a easy solution to my problem. I’m pretty new to developing and GDevelop so still a lot of trial and error the game is a top down movement. I have a global variable called “Directions” that i want to change every few seconds so the enemy will move in a different direction.

imgur.com/a/6AxCVPz

  • The time to check the timer should be greater than zero, otherwise, you’ll change the direction variable every frame:
Conditions: The timer "Directions" is greater than 5 seconds    // Change direction every 5 seconds
  • You’re mixing a scene timer and an object timer, the condition is using a scene timer and the action resets an object timer… without an object being set.
  • Take into account that Random(2) can return 0 too! (maybe it’s by design) :slight_smile:

I think that fixing these two (or three) problems will make it work nicely :smiley:

Thanks for the quick response, i have tweaked with your input and its working. The Random(2) is taken in account im using 0 as a stop so its not moving all the time.

Got in a bit of situation that i don’t know how to solve with the random(). The problem that i have is that every enemy is moving in the same direction of the random() is there a easy way to separate the random for every enemy or do i need to make different random() for each enemy?

Yup, you need a for-each object loop and object variables:

[code]For each object Enemy:
Conditions: No conditions (always)
Actions: Do = Random(2) to variable Direction of Enemy

Conditions: Variable Direction of Enemy is = 1
Actions Add force of 0;200 to Enemy

Conditions: Variable Direction of Enemy is = 2
Actions Add force of 200;0 to Enemy[/code]

Also, now you can use object timers to make each enemy change direction independently, right now they all change directions at the same time :slight_smile:

Thanks for the quick reply as always =)

I have tested what you wrote but nothing is moving, im missing something easy but cant figure it out.

imgur.com/u1UOaDg

Ah, an easy one!

Directions is an object variable, but in your conditions you are testing the value of a scene variable called Directions.

The condition should read:

Variable Directions of Monster is =1

Go to All objects>Variables and pick the variable from there.

Thanks for the reply it solved one problem but now its only moving only 1 object.

imgur.com/a/hplxsql

The timer must be an object timer too :smiley:
The object timers feature is new, just replace the two timers condition/action by the object timer ones and it will work fine :slight_smile:

I feel so stupid, thanks for the quick reply.