D
dcamod
Guest
Hello! I am trying to program a steering behavior with more control over acceleration and deceleration.
The issue I am having is the object will act erratically. It will not start motion without getting close first and if I circle the mouse around it will shoot itself off the screen while trying to correct its direction.
Here is all the code I have running in the room and on the object.
Any help is appreciated. Thank you
The issue I am having is the object will act erratically. It will not start motion without getting close first and if I circle the mouse around it will shoot itself off the screen while trying to correct its direction.
Here is all the code I have running in the room and on the object.
Code:
///sb_seek(x,y,_weight)
var _target = vect2(argument[0],argument[1]);
var _weight = argument[2];
var _desired = vect_subtract(_target,position);
var _desired_mult = maxSpeed/_weight;
_desired = vect_multr(_desired,_desired_mult)
if point_distance(x,y,argument[0],argument[1]) > slow_radius
{vect_add(_desired,velocity);}
if point_distance(x,y,argument[0],argument[1]) <= slow_radius
{_force = vect_subtract(_desired,velocity);}
var _force_mult = (maxForce/maxSpeed)
_force = vect_multr(_force,_force_mult)
return _force;
Code:
position = vect2(x,y);
velocity = vect2(0,0)
steering = vect2(0,0)
maxSpeed = .5
maxForce = .5
_force = vect2(0,0)
slow_radius = 256
Code:
///steer
image_angle = point_direction(x,y,mouse_x,mouse_y)
if point_distance(x,y,mouse_x,mouse_y) > 64
{
steering = vect2(0,0)
steering = vect_add(steering,sb_seek_debug(mouse_x,mouse_y,20))
velocity = vect_add(velocity,steering)
position = vect_add(position,velocity)
x = position[1]
y = position[2]
}
Any help is appreciated. Thank you