M
Matt93
Guest
I'm trying to code oscillating movement for my player. Basically, the player has a parachute, and is floating in the air. When he's idle (when there's no keyboard input) I want him to rotate slightly to the right, then back towards the left in an oscillating movement. I've written code that works, but I feel like there's a better way of doing it. I've had to use a variable which triggers to false when I want him to tilt in one direction, then to true when he tilts in the other. Here's my code:
Is there a less clunky way of doing this without needing an additional variable? Cheers!
Code:
//Tilt player
if (forth) //counter clockwise
{
image_angle ++;
if (image_angle >= 30)
{
forth = false; //this variable is set to false when player needs to tilt clockwise
}
}
if (!forth) //clockwise
{
image_angle --;
if (image_angle <= -30)
{
forth = true; //true so player tilts counterclockwise
}
}