Hi all, I’m a JS developer, who’s trying out GDevelop.
I would like to:
Spawn an Enemy (I’ve got an Object named Enemy) every 1.5s seconds.
Move the spawned enemy either in X or Y, with a fixed distance of 150 pixels, every 1.5s.
Below are some parts of the logic that I’ve tried (obviously it should not be simply +150 etc.) but have had no luck. Below I would expect 1 enemy to spawn at the top left, and simply move 150 pixels right, each 1.5 seconds.
I tried programming this, but it seems that the Javascript window is a runtime loop, so I can’t do “setInterval”.
wait, so your enemy is not changing position?
if so, do the change position event first, then reset the timer.
what you can do is do a random roll with a variable.
timer move >1.5 secs do Randominrangewithsetp(0,1,1) to variable random
subevent variable random =0 do EnemyX+150
variable random =1 do enemyY+150
reset timer
Just to be clear, changing position will make it teleport, not walk.
As it is, GDevelop doesn’t know which enemy instance you want to move.
You should use a For each loop, or a Pick all action.
Or, if you use an object timer instead of a scene timer, each instance will have one timer which will be used for instance filtering.
you can use behaviors.
if double you click on the objects on the topright you find behaviors. there you find pathfinding.
give your objects variabes DestinationX and DestinationY
then use your event to change thos variables and use pathfinding action to move to the destinations.
events dont line up like that. they need ther own events.
right now everything is 1 single event and a condition with dir =0 and also dir = 1 can never be true.each one must be its own subevent with the corresponding actions.
also reset the timer last! last subevent reset timer.