Skip to main content
GameDev.net gamedev.net
🔒 Locked

Updating Rotation problem

Started by BlackSeeds Oct 7, 2008 at 2:28 PM 1 replies 550+ views
Original Post
BlackSeeds
BlackSeeds
Hi, I've got an issue in XNA which is driving me insane and I'm confused as to whats going on. Basically I'm new to XNA but experienced in OpenGL and Direct X with c++. I want to tween between rotations for a tank game so when you press the analog stick you new rotation is set to the orientation of the stick, and for smooth movement I want to blend between current rotation and the new rotation. Simple enough, I have already implemented similar things before so just did the code as usual and expected it to work... but no it doesn't. what I get is the sprite randomly spinning around franticly before it stops,

//intialisation
int baseRotation = 0;
int intRot = 45;

        public void move(GameTime gameTime)
        {
            if (baseRotation < intRot)
            {
                int diff = intRot - baseRotation;

                if (diff <= 5)
                {
                    baseRotation = intRot;
                }
                else
                {
                    baseRotation++;
                }
            }
            else
            {
                baseRotation = intRot;
            }
        }


So from the above source, you would expect baseRotation to update to 40 then get set to the same as intRot and then thats it. If I debug and step through, this happens, just if I run the game it doesn't, it just spins around a few times and then eventually stops. I just call the update function move from inside my main update function. Anyone had any experience of this or am I doing something silly along the way? Just a quick note, I'm not updating based on time or using floats because I initially thought that this was causing the issue but evidently not.
sirob
sirob
Rotation is usually expressed in radians, not in degrees. This means that 45 is actually somewhere at around 14 full turns from 0. So if you're trying to go from 0 to 45 your sprite will turn 14 times before stopping. Also, since you're adding 1 each frame, it'll just in steps of around 60 degrees each frame.

Of course, if you're dividing by 180/PI somewhere in your code, that's probably not the problem. If not, either change your logic to use radians or divide by 180/PI.
Sirob Yes.» - status: Work-O-Rama.
BlackSeeds
BlackSeeds
yeah i convert to radians before rendering, just used degrees so i could use ints to rule out any issues with floats,

however ill double check that the radians calculation is working correctly to rule out this issue.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.