Rotate a sprite in the direction of it's movement vector
Pergunta
I've got an XNA Windows Phone Game and you move a sprite with the accelerometer
My problem is that I can't figure out how to make the sprite face the direction it is moving. So far this is my code:
arrowPos.Y += -accelState.X*10;
arrowPos.X += -accelState.Y*10;
rotation = -(float)Math.Atan2(arrowPos.Y, arrowPos.X);
Solução
Your current rotation
calculation uses the current position of the sprite - the sprite may be in that position whether it is moving north or west.
Try using the accelState.X
and accelState.Y
values instead.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow