Page 1 of 2

Enemy move

PostPosted: Wed 26 Sep 2018, 09:33
by Sasser
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

Re: Enemy move

PostPosted: Wed 26 Sep 2018, 12:48
by Lizard-13
* 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

Re: Enemy move

PostPosted: Wed 26 Sep 2018, 15:30
by Sasser
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.

Re: Enemy move

PostPosted: Tue 2 Oct 2018, 23:15
by Sasser
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?

Re: Enemy move

PostPosted: Wed 3 Oct 2018, 03:36
by Lizard-13
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 :)

Re: Enemy move

PostPosted: Wed 3 Oct 2018, 19:55
by Sasser
Thanks for the quick reply as always =)

Re: Enemy move

PostPosted: Thu 11 Oct 2018, 00:03
by Sasser
I have tested what you wrote but nothing is moving, im missing something easy but cant figure it out.

https://imgur.com/u1UOaDg

Re: Enemy move

PostPosted: Thu 11 Oct 2018, 00:11
by MattLB
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.

Re: Enemy move

PostPosted: Thu 11 Oct 2018, 09:16
by Sasser
Thanks for the reply it solved one problem but now its only moving only 1 object.

https://imgur.com/a/hplxsql

Re: Enemy move

PostPosted: Thu 11 Oct 2018, 12:28
by Lizard-13
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 :)