KappaPraise
Member
Hello, I am using mouse to set direction for my object (specifically direction, not image_angle) and I need to figure out shorter way for rotation.
I tried formula
Below is my attempt. As a result only 1st mouse click rotates object to correct angle, all following clicks makes object rotate infinitely. Any ideas please?
GLOBAL RIGHT PRESSED EVENT:
STEP EVENT:
I tried formula
direction += sin(degtorad(target_direction - direction)) * rspeed;
but I need object rotate at constant speed.Below is my attempt. As a result only 1st mouse click rotates object to correct angle, all following clicks makes object rotate infinitely. Any ideas please?
GLOBAL RIGHT PRESSED EVENT:
GML:
dir = point_direction(x, y, mouse_x, mouse_y);
if dir < 180
{
turn_direction = "Left";
turn_amount = floor(dir / turn_speed)
turn_last = dir % turn_speed
show_debug_message(string(dir))
show_debug_message(string(turn_amount))
show_debug_message(string(turn_last))
}
else
{
turn_direction = "Right";
turn_amount = floor((360 - dir) / turn_speed)
turn_last = (360 - dir) % turn_speed
show_debug_message(string(dir))
show_debug_message(string(turn_amount))
show_debug_message(string(turn_last))
}
GML:
if direction != dir
{
if turn_counter != turn_amount
{
if turn_direction == "Left"
{
direction += turn_speed;
image_angle = direction;
}
else
{
direction -= turn_speed;
image_angle = direction;
}
turn_counter++;
}
else
{
if turn_direction == "Left"
{
direction += turn_last;
image_angle = direction;
}
else
{
direction -= turn_last;
image_angle = direction;
}
turn_counter = 0;
}
show_debug_message(string(direction) + " / " + string(dir))
}