Sign in to follow this  

XNA Sprite Rotation question

This topic is 4015 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am attempting my first game of any type, using XNA. Basically trying to do an Atari type Tank game. I have managed to setup full screen, add a tank sprite, and implement keyboard movement. Trying to keep it simple one step at a time. My next challenge was to implement rotation. I have managed to get the tank to rotate in circles, clockwise and counter-clockwise. Again keeping it simple, I am using the standard WASD keys for movement. W moves the tank forward, S moves it backward. Now here is my problem, how do I adjust movement based on the rotation of the tank?? The tank starts facing straight down, and so far I can move it up and down the Y axis, the rotation allows for turning, but, not sure how to calculate X and Y values based on direction. Any help would be appreciated. Thanks, Shawn

Share this post


Link to post
Share on other sites
Here's the update method I used for an old game I wrote a while back with a similar control scheme to that:

private const double mathpioneeighty = Math.PI / 180;

public void Update(float delta)
{
if (mVelocity > 0f)
{
double radian = (double)mDirection * mathpioneeighty;
float scale = mVelocity * delta;
x += (float)Math.Cos(radian)* scale;
y += (float)Math.Sin(radian)* scale;
}
}


In this code, I'm storing the direction as an angle in degrees (mDirection), and the velocity (mVelocity) as a scalar value.

Share this post


Link to post
Share on other sites

This topic is 4015 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this