Rotate sphere to the direction of movement
Image a 3D rigidbody ball with the blue square on top. This is my character (see picture 1.). Below is the script I use for moving the ball.
void FixedUpdate()
{
if (Input.GetKey(KeyCode.W))
rb.AddForce(Vector3.forward);
if (Input.GetKey(KeyCode.S))
rb.AddForce(Vector3.back);
if (Input.GetKey(KeyCode.D))
rb.AddForce(Vector3.right);
if (Input.GetKey(KeyCode.A))
rb.AddForce(Vector3.left);
}
Now, I move forward and the ball rolls forward (see picture 2.). The top of the ball (blue square) is now facing the front. Here comes the tricky part for me. When I move left/right I want the ball to rotate first and then move (see Picture 3. <-- link). In other words, I want the blue square to be always facing the direction of movement, therefore getting in contact with the floor every full roll. What previously (from the ball perspective) was right direction, should now be forward again. I would appreciate any sort of help. Thank you in advance.
Your answer
Follow this Question
Related Questions
How to move whilst airborne (using standard third person character script)? 0 Answers
Rotating Two Axes for Gravity,Rotating only two axes towards Object 0 Answers
Keep position of CharacterController relative to rotating platform 0 Answers
Character Rotation 0 Answers
Sideways force calculation with 8 directional movement 0 Answers