move an object a certain distance toward another object

Hi, so in a top-down viewed game, how can I make an object jump towards another object but only a certain amount of steps?
I don't mean it to move at speed, then I could use motion_set() i believe, but instead to jump an amount of steps toward the intended other object.
 

woods

Member
set the target x,y
move n pixels towards the target..


something like this?


if point_distance(x, y, target.x, target.y) > 5
{
move_towards_point(target.x, target.y, 5);
}
else speed = 0;
 
set the target x,y
move n pixels towards the target..


something like this?


if point_distance(x, y, target.x, target.y) > 5
{
move_towards_point(target.x, target.y, 5);
}
else speed = 0;
hi, not exactly, what I meant was so that the object intended to move would just 'jump' to the new position closer towards the other object, not move towards it at any speed. Its likely to do with a combination of direction and x and y values but I don't really know how... thanks for response
 

Reprom

Member
function ThisCoolFunctionPrehaps(x_target, y_target, distance) {
var dir = point_direction(x, y, x_target, y_target);
x = lengthdir_x(distance, dir);
y = lengthdir_y(distance, dir);
}
 
Actually, it is not going to work. I made a mistake and forgot that you need to add lengthdir instead.

x += lengthdir_x(distance, dir);
y += lengthdir_y(distance, dir);
THIS is it! i felt like id forgotten something essential. that was lengthdir(). this should definitely do the job. thanks a ton
 
Top