• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Translation help

I

Isurvolte

Guest
Hello, im actually trying to move a bar from a point A to a point B (not a teleportation) and I tried to use
"move_towards_point", it works but the movement doesn't stop and I can't fix that (tried while function tho) , can you help me ?
Thanks.
 

FrostyCat

Redemption Seeker
move_towards_point() is only responsible for starting the movement, it is not responsible for stopping the movement. You need to do it another way.

In your Create event, you should set a target coordinate and a stepping increment:
Code:
target_x = x;
target_y = y;
step_size = 4;
And in the Step event, it should make one unit of action towards reaching the target coordinate, if it isn't already there:
Code:
if (x != target_x || y != target_y) {
  if (point_distance(x, y, target_x, target_y) <= step_size) {
    x = target_x;
    y = target_y;
  } else {
    mp_linear_step(target_x, target_y, step_size, false);
  }
}
Then you simply set target_x and target_y and leave the code time to work. DO NOT use a blocking loop for this, and DO NOT be a start-to-end control freak again the way you did by attempting a while loop. Set yourself a touch-and-go interface and give it leeway to run. You are only supposed to put in food and enter the time on a microwave oven. You are NOT supposed to be the one turning the dish or counting down the timer, the microwave oven is.

It's absolutely essential for rookies to get a grip on the difference between loop-based repetition and step-based repetition. Anything that needs to repeat over time should NEVER be done using blocking loops (e.g. for, while, do-until, repeat). It needs to have bite-sized units of action in a repeating event that does it gradually for you, not a blocking loop that does everything at once.
 
Top