Ask here your questions to get help using GDevelop.
By Sasser
#68268 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.

https://imgur.com/a/6AxCVPz
User avatar
By Lizard-13
#68271 * The time to check the timer should be greater than zero, otherwise, you'll change the direction variable every frame:
Code: Select allConditions: 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) :)

I think that fixing these two (or three) problems will make it work nicely :D
By Sasser
#68272 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.
By Sasser
#68337 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?
User avatar
By Lizard-13
#68340 Yup, you need a for-each object loop and object variables:
Code: Select allFor 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


Also, now you can use object timers to make each enemy change direction independently, right now they all change directions at the same time :)
By MattLB
#68414 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.
User avatar
By Lizard-13
#68421 The timer must be an object timer too :D
The object timers feature is new, just replace the two timers condition/action by the object timer ones and it will work fine :)