[Solved] How to change sprites according to angles

epicguy

Member
In the obj_gun object, and within it's step event, I have this:
GML:
x = obj_player.x;
y = obj_player.y;
image_angle = point_direction(x,y,mouse_x,mouse_y);
direction = image_angle;
if (image_angle > 180) {
    sprite_index = spr_gunright;
} else {
    sprite_index = spr_gunleft;
}
And so, this is supposed to change the gun sprite to be pointing right if the cursor is on the right side of the player, and left if it is on the left side. However, this does not work. Any way on how to make it work?
 

Slyddar

Member
Gamemaker angles start at 0 to the right and go counterclockwise, so you want 2 checks, if image_angle < 90 or image_angle > 270.
 

epicguy

Member
Gamemaker angles start at 0 to the right and go counterclockwise, so you want 2 checks, if image_angle < 90 or image_angle > 270.
So like this?
GML:
x = obj_player.x;
y = obj_player.y;
image_angle = point_direction(x,y,mouse_x,mouse_y);
direction = image_angle;
if (image_angle < 90) {
    sprite_index = spr_gunright;
}
if (image_angle > 270) {
    sprite_index = spr_gunleft;
}
Because that doesn't work properly.
 
More like:

GML:
if (image_angle < 90 || image_angle > 270) {
    sprite_index = spr_gunright;
}
else {
    sprite_index = spr_gunleft;
}
 

Slyddar

Member
GML:
if (image_angle < 90)
  { sprite_index = spr_gunright; }
if (image_angle > 270)
  { sprite_index = spr_gunleft; }
Because that doesn't work properly.
From what you tried, I guess you still don't understand my description on how angles work. Would help your skills if you actually understood the code @Mushroomstick gave you instead of just plugging it in.
 
Top