Object not moving smoothly when randomly picking spots

I am trying to make an object pick a random number from 1 to 3 and going to on top of the corresponding object (objects being LeftUpSpot, LeftMiddleSpot and LeftDownSpot). After that it waits three seconds and goes back to the spot it started from and repeate.

Object should be smoothly moving to the spots by using tweens and random logic.

Object starts to stutter and wiggle around and seems to only go to the middle spot (so LeftMiddleSpot object and number two on the randomizer) then goes smoothly back to the original spot (LeftDefaultSpot).

I’m following the tutorial for boss fights in the GDevelop YouTube channel.

Screenshot of the code logic I’m using.

Circle sprites are the spots (LeftUpSpot, LeftMiddleSpot, LeftDownSpot and LeftDefaultSpot (the one on the top middle)). White square on the top is LeftHand object that is supposed to be moving smoothly. Other objects can be ignored. Ratmech object is hidden because I don’t want to show the final boss of my game.

I think its the very first Event from the first screenshot.

The one where you set the random number from 1 to 3, it needs a trigger once.

Whats happening is, while its 0 and the 3 seconds havent gone by, the event is being triggered 60 times per second, so its like your queueing up 180 random numbers :stuck_out_tongue:

Thats why hes wiggleing, its because hes constantly trying to change position.

Add a trigger once to that event and it should fix it!

Here is a simple approach using pick random object instead of random(). You can use a group or copies of the same object.

The collision event is used to remove the current waypoint from the possible new location so it can’t pick the same waypoint twice in a row. I used a random number for the wait to add some randomness. I used float so instead of just a 1 or 2 second wait, it could also be any value like 1.7

2 Likes

That only makes the object go to the middle spot and default spot.

This helped. Thanks for your help.

1 Like