Z
Ziliock
Guest
How can I change gradually the direction of an object to make it pursue another object?
Thanks by the way
Thanks by the way
/* This script will smoothly rotate the calling instance to a specified point.
Arguments:
0 = target x position
1 = target y position
2 = maximum rotate speed (must be positive)
3 = a damping factor (acceleration) as a value between 0 and 1*/
var dir, spd, dmp, rot;
dir = point_direction(x, y, argument0, argument1);
spd = max(argument2, 0);
dmp = clamp(argument3, 0, 1);
image_angle -= clamp(angle_difference(image_angle, dir) * dmp, -spd, spd); //Smoothly rotate to aim position.
var dir_to_target = point_direction(x,y,target.x,target.y);
var diff_an = angle_difference(dir_to_target,old_dir_to_target);
direction += min(turn_rate,abs(diff_an))*sign(diff_an);
old_dir_to_target = dir_to_target;
Let me see.I think I'm use (x1, y1, x2, y2) like:Get the direction of your object by using point_direction(x1, y1, x2, y2) (1 is your pursuing object, 2 is your object being pursued)
Get the direction your missile is moving by using 'direction'
Check to see if these are not the same value
In the step event of the missile, If missiles direction and the direction to the object it is homing are not the same value, adjust your missile's direction to be closer to the value found using point_direction (however much you adjust it will essentially be its turning rates per frame measured in degrees)
Thanks a lot you know?But I'm alrready know that formula.You can get pretty okay homing like this; I use it for flying enemies a lot. (Except with code, but you don't seem to like/appreciate that, so here's how to do it with DND)
If y is smaller than player y,
add 0.2 to vertical speed.
else
subtract 0.2 from vertical speed.
If x is smaller than player x,
add 0.2 to horizontal speed.
else
subtract 0.2 from horizontal speed.
var a = point_direction(x, y, target.x, target.y);
direction += sign(dsin(a - direction)) * 5;
image_angle = direction;
Just I put that in the write code's action?try this for the missile
That should workCode:var a = point_direction(x, y, target.x, target.y); direction += sign(dsin(a - direction)) * 5; image_angle = direction;
Thanks you!How can I slow the speed?try this for the missile
That should workCode:var a = point_direction(x, y, target.x, target.y); direction += sign(dsin(a - direction)) * 5; image_angle = direction;
speed = point_distance(x, y, target.x, target.y) / slowdownSpeed;
Sorry it was a problem with the object who is partent of ittry this for the missile
That should workCode:var a = point_direction(x, y, target.x, target.y); direction += sign(dsin(a - direction)) * 5; image_angle = direction;
It works perfectly.Thanks a lotThat code doesnt work?