Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make a character make an oscillation move. That is, the character will start by rotating to a certain angle, say 60 degrees, and then slowly come back to an upright position then rotate to the opposite direction for an angle less than 60, say 55, and do it all again until the rotation angle reaches zero and the character stops. Currently I'm trying to achieve this by declaring global variables and checking them with if blocks and changing their value by 1 degrees in those blocks so that each time the timer calls paintgl it decreases the angle by 1 degree and draws the object thus making it look like it's slowly rotating. I'm having trouble with stopping the character. This is the part of my code that handles it;


j = j + 2;
 if (j == 0)
   k = 60;
   flag = !flag;



k = k - 2;
if(k == 0)
    j = -60;
    flag = !flag;

gluCylinder(player, 1,1,8,100,100); Here the cylinder is my character and the if blocks are increasing/decreasing the global variables j and k. j is initialized to -60 and k is initialized to 60.

what i want to do is to make the character lean to the ground for an angle by the click of a mouse and when the mouse is released, the character will slowly go upright and lean on to the other direction, then slowly go upright again and lean on to the first direction and so on.

How can I make this thing work and how can I stop it. Thanks in advance.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.