|
Yes you could still do what I suggested, this is simply physics/calculus. rate of change = distance/time.
My original suggestion was this which gives us an exponential graph where velocity is the y-axis and distance is the x-axis.
// with a room speed of 30 steps/frames per second you will get these speeds // distance = 5, 5/10th pixel per step * 30 steps per second = 15 pixels per second // distance = 10, 10/10th pixel per step * 30 steps per second = 30 pixels per second // distance = 20, 20/10th pixel per step * 30 steps per second = 60 pixels per second var spd; spd = distance_to_point(xx, yy) / 10; // you could also limit the speed if you like to some arbitrary value if (spd > 30) { spd = 30; } move_towards_point(xx, yy, spd);
So let's just spruce up what I suggested first and you'll get a function similar to what you want that will accelerate up to a constant distance from any given point at which point it will slow down. You'll need to create a new variable called velocity in your create event and initialize it to 0.
var dist; dist = distance_to_point(xx, yy); if (dist > 100) { // accelerate velocity += dist / 10; } else { // we are getting close, so decelerate velocity -= (100 - dist) / 10; }
// you could also limit the speed if you like to some arbitrary value if (velocity > 30) { velocity = 30; } move_towards_point(xx, yy, spd);
If you like you can also use the built in variables with this alternative so you don't have to create a new one and you could also use the friction variable then as well.
var dist; dist = distance_to_point(xx, yy); if (dist > 100) { // accelerate speed += dist / 10; } else { // we are getting close, so decelerate speed -= (100 - dist) / 10; }
// you could also limit the speed if you like to some arbitrary value if (speed > 30) { speed = 30; }
direction = point_direction(x, y, xx, yy);
|