0
\$\begingroup\$

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

\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Now the rotation is smooth, although he doesn't speed up... \$\endgroup\$
    – user26188
    Commented Feb 11, 2013 at 13:28
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Evan
    Commented Feb 11, 2013 at 14:19

Not the answer you're looking for? Browse other questions tagged .