Legacy GM Changing sprite at a certain angle

B

BenSunhoof

Guest
So here's the deal. As beginner practice, I'm making a very simple top-down shooter where my character shoots with his middle finger (yeh) which follows my mouse cursor. I've figured out how this is done, but what bothers me is that I can't change the yscale at a certain angle so that the hand turns around, otherwise it looks like the player shoots behind his back or something.
Here's what I tried to do:
Code:
if (90 < image_angle < 270)
image_yscale = -1
else
image_yscale = 1;
But when I run the game, the hand stays in the -1 yscale at any angle, and I don't understand why. Does anyone have an idea what might be the solution?
 
Last edited by a moderator:
C

CreatorAtNight

Guest
What you probably want to do is make the sprite rotate so it always points in the right direction. put this in the STEP or DRAW event for your player object:
Code:
image_angle = (point_direction(x,y,mouse_x, mouse_y));
This will take the X and Y from the player object, draw an imaginary line to the mouse X and Y and calculates the angle of the line, than it rotates your sprite at that angle.
If the angle is not right when you use this code, it will be because the initial angle of your sprite is not right. You might have to rotate your sprite in the sprite editor to correct this. : )
Let me know if you need help.
 
B

BenSunhoof

Guest
What you probably want to do is make the sprite rotate so it always points in the right direction. put this in the STEP or DRAW event for your player object:
Code:
image_angle = (point_direction(x,y,mouse_x, mouse_y));
This will take the X and Y from the player object, draw an imaginary line to the mouse X and Y and calculates the angle of the line, than it rotates your sprite at that angle.
If the angle is not right when you use this code, it will be because the initial angle of your sprite is not right. You might have to rotate your sprite in the sprite editor to correct this. : )
Let me know if you need help.
The thing is I already did this step. This exact line of code is in the step event for my obj_hand. But when I rotate the hand 180 degrees it points down with its thumb, that's why I want to flip it in y axis.
 
C

CreatorAtNight

Guest
Ah I see what you mean, well in that case, the if statement in your code isn't right.
If you want to flip when the image_angle is both bigger than 90 and smaller than 270 you have to do it like this:
Code:
if (image_angle > 90 && image_angle < 270) {
   image_yscale = -1;
} else {
   image_yscale = 1;
}
You can only do one comparison per if statement parameter. so to make two comparisons you use the && to make it check if both of those statements are true.
If you would have two comparisons and you only need one of them to be true you use || instead of &&.

EDIT: whoops, you also forgot the brackets. :)
 
B

BenSunhoof

Guest
Ah I see what you mean, well in that case, the if statement in your code isn't right.
If you want to flip when the image_angle is both bigger than 90 and smaller than 270 you have to do it like this:
Code:
if (image_angle > 90 && image_angle < 270) {
   image_yscale = -1;
} else {
   image_yscale = 1;
}
You can only do one comparison per if statement parameter. so to make two comparisons you use the && to make it check if both of those statements are true.
If you would have two comparisons and you only need one of them to be true you use || instead of &&.

EDIT: whoops, you also forgot the brackets. :)
It worked fine without brackets, thank you so much.
 
C

CreatorAtNight

Guest
Oh really? I didn't even know, Game Maker is pretty forgiving when it comes to syntax : )
 
Top