• 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 SOLVED - Problem with state machine. Won't find X.

Heyo.

I've got a state machine and in one of the steps the instance is supposed to go back to it's original position.

The code is
Code:
move_towards_point(xstart, ystart, 2);
if (x = xstart) state = idlerState.IDLE;
The first line is working but the instance doesn't stop at "xstart", it's.... sort of vibrating in it's position so the following "if statement" is never met.

Someone please put me out of my misery?
 

FrostyCat

Redemption Seeker
You've fallen for the classic noob trap known as target jitter. Trade in your expectation of an exact match for a tolerance range.
Code:
move_towards_point(xstart, ystart, 2);
if (point_distance(x, y, xstart, ystart) < 2) {
  x = xstart;
  y = ystart;
  speed = 0;
  state = idlerState.IDLE;
}
 

Sabnock

Member
you are also repeatedly calling the move_towards() function when, in your supplied code, you only need to use it once. Unless there is something else influencing the speed and direction of the instance?
 
You've fallen for the classic noob trap known as target jitter. ...
Wish I had seen that post before posting. That makes perfect sense.. although I'd never had figure it out. Many thanks!
Edit: And of course it's working like a charm. Again: thank you!

... Unless there is something else influencing the speed and direction of the instance?
There is, I only referenced the lines that didn't work. Good point though, thanks!
 

GMWolf

aka fel666
You've fallen for the classic noob trap known as target jitter. Trade in your expectation of an exact match for a tolerance range.
Code:
move_towards_point(xstart, ystart, 2);
if (point_distance(x, y, xstart, ystart) < 2) {
  x = xstart;
  y = ystart;
  speed = 0;
  state = idlerState.IDLE;
}
Would be worth keeping a script around like that.
move_to_point or something.
 
Top