Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question already has an answer here:

I would like to rotate my Player very smooth. At the moment the player stops rotating when I release the button. Also the rotation should get faster, if the player rotates longer. I use XNA and have no idea how to solve this.

Sry for my english, I hope you understand what I mean.

Michi

share|improve this question

marked as duplicate by Byte56, Sean Middleditch, Josh Petrie, Trevor Powell, bummzack Feb 13 '13 at 8:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer 1

up vote 0 down vote accepted

you could try something like this

float turnSpeed;
if (KeyBoard.GetState().IsKeyDown(Keys.Right))
    turnSpeed++;
if (KeyBoard.GetState().IsKeyDown(Keys.Left))
    turnSpeed--;

 RotationAngle += turnSpeed;
 //Adjust what you multiplay turnSpeed for how long you want him to stay spinning.
 turnSpeed *= 0.89f;

He should now speed up while turning, then when you release the turning keys on the keyboard he should spin a tiny bit then stop.

share|improve this answer
    
Now the rotation is smooth, although he doesn't speed up... –  user26188 Feb 11 '13 at 13:28
2  
This code initializes a new variable called turnSpeed each update, meaning it never changes in magnitude because it is always initialized to its default value each time. You need to use a variable that maintains an appropriate scope for your rotational velocity. –  Evan Feb 11 '13 at 14:19
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.