move_towards_point in alarm

berczi17

Member
Hi!


I use the move_towards_point function, but I have a weird issue.

If I use it in the STEP event, it’s works perfectly, but in ALARM it” “vibrating” on the endpoint.



// with STEP (it works)


//Step:

if (global.ACTION = 1)
{
DISTANCE = point_distance(x, y, 32, 160);

move_towards_point(32, 160, min(5, DISTANCE));

}


////////////////////////////////////////////////////////////////////////////////////////


// with ALARM (it doesn’t works)


//Step:

if (global.ACTION = 1)
{
if (alarm[0] == -1)
{
alarm[0] = 30;
}
}


// alarm[0]:

DISTANCE = point_distance(x, y, 32, 160);

move_towards_point(32, 160, min(5, DISTANCE));
 
A

Alex_Beach

Guest
That's because you're moving at a speed that is greater than the distance of the final point compared to the frame before the final point. You could always make the alarm a flag variable. Example: in the alarm: move=true. Step event: if (move==true) move_towards_point
 

TheouAegis

Member
Think of it this way, every 30 steps you update the direction of travel when you use an alarm. If he is just step of that, then you're updating the direction of travel on every single step. With the alarm, you will constantly be moving at a speed of 5 pixels per step. With the step event, you will start off moving with a speed of 5 pixels per step until you are close enough that you can move at a lower speed. In other words, with an alarm, you always move 150 pixels if you are more than 5 pixels away when the alarm fires.
 
Top