R
Richard Mountain
Guest
Objective:
I'm trying to get an image to rotate ( with animation ) towards the angle where I click on screen via the shortest route.
For example:
image_angle = 10
point_direction = 140
This time image will rotate clockwise.
( I have this working up until the point image_angle reaches 360, then it breaks going from 360 to 0.. 1.. 2.. etc..).
I'm struggling with:
image_angle = 10
point_direction = 220
This time the image should rotate anti clockwise.
Here is what I have up to now, is there a simpler solution?
I'm trying to get an image to rotate ( with animation ) towards the angle where I click on screen via the shortest route.
For example:
image_angle = 10
point_direction = 140
This time image will rotate clockwise.
( I have this working up until the point image_angle reaches 360, then it breaks going from 360 to 0.. 1.. 2.. etc..).
I'm struggling with:
image_angle = 10
point_direction = 220
This time the image should rotate anti clockwise.
Here is what I have up to now, is there a simpler solution?
Code:
/// Ship movement logic
direction = obj_player.image_angle;
if ( global.attack_current_angle )
{
// Rotate image
// Check for shortest route
if ( ( direction + 180 ) > global.attack_current_angle )
{
// Shorter route is +
direction += 3;
// If the value reaches 360 the need to convert it to 0
if ( direction >= 360 ) direction = 0;
// Player angle > clicked point then stop
if ( direction > global.attack_current_angle )
{
direction = global.attack_current_angle;
global.attack_current_angle = false;
}
}
else
{
// Shorter route is -
}
}
else
{
// Check to see whether mouse has been clicked
if ( !ds_queue_empty( global.attack_queue ) )
{
// Mouse has been clicked
global.attack_current_angle = ds_queue_dequeue( global.attack_queue );
}
}
obj_player.image_angle = direction;
// Debug
global.debug_text[0] = "Image Angle: " + string( obj_player.image_angle );