Thanks for reply, I Changed my code like:
| public void TurnTo(Vector2 turnTo) |
| { |
| m_Direction = turnTo - m_CurrentPosition; |
| double dNewRotation = 0; |
| float fDirection = 0.5f; |
| if (m_Direction.X != 0 && m_Direction.Y != 0) |
| dNewRotation = Math.Atan2(m_Direction.Y / m_Direction.X, turnTo.Y / turnTo.X); |
| else if (m_Direction.X == 0 && m_Direction.Y > 0) |
| fDirection = 0.0f; |
| if (m_Direction.X < 0) |
| dNewRotation -= (Math.PI * fDirection); |
| else |
| dNewRotation += (Math.PI * fDirection); |
| if (dNewRotation < 0) |
| dNewRotation += (Math.PI * 2); |
| m_Rotation = (float)dNewRotation; |
| } |
And
| m_CurrentPosition -= Vector2.Normalize(m_Direction); |
Thanks for reply, It solved my problem :)
But somehow, i think i'm doing something wrong with Right and Left actions, i'm tryin:
| if (m_CurrentKeyboardState.IsKeyDown(Keys.D)) |
| { |
| m_CurrentPosition.X += Vector2.Normalize(m_Direction).Y; |
| m_CurrentPosition.Y -= Vector2.Normalize(m_Direction).X; |
| m_CurrentAnimationIndex = 2; |
| m_CurrentState = CharacterState.Walking; |
| } |
| if (m_CurrentKeyboardState.IsKeyDown(Keys.A)) |
| { |
| m_CurrentPosition.X -= Vector2.Normalize(m_Direction).Y; |
| m_CurrentPosition.Y += Vector2.Normalize(m_Direction).X; |
| m_CurrentAnimationIndex = 2; |
| m_CurrentState = CharacterState.Walking; |
| } |
Am i doing something wrong ?
D is Right, and A is Left Key of my game.