1
\$\begingroup\$
if (controller.isGrounded) {
                        moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
                        moveDirection = transform.TransformDirection (moveDirection);
                        moveDirection *= speed;
                        if (Input.GetButton ("Jump"))
                                moveDirection.y = jumpSpeed;

                }
                moveDirection.y -= gravity * Time.deltaTime;
                controller.Move (moveDirection * Time.deltaTime);

This works. I can manover my player in any direction.

With the awsd keys i can create 8 directions. I would like player to rotate towards the direction of the keys pressed. This is a top down game. So W+D would take you diagonally right/up. S+D would take you diagonally right/down.

I want the player to rotate into that direction, but also move the direction it is facing. Like a car. So if it is facing a complete different direction then it would actually move not in the target direction for a while until it has the target direction. Am i making sense?

      if (moveDirection != Vector3.zero) 
    {
transform.rotation = Quaternion.LookRotation (moveDirection);
                        }
\$\endgroup\$
3
  • \$\begingroup\$ Do you actually want the face direction follow the movement direction or the movement direction to follow face direction? In other words, should the move controls be relative to window orientation or player's face direction? The latter approach is used more often in games. As a side note, I don't think that a GetAxis method should take the desired axis as string parameter. \$\endgroup\$
    – danijar
    Nov 21, 2013 at 7:19
  • \$\begingroup\$ GREAT POINT @danijar !!! I want the move direction to follow the face direction. Lika a veichle on wheels. Thanks for clarifying it. \$\endgroup\$
    – Daarwin
    Nov 21, 2013 at 9:44
  • \$\begingroup\$ I'm glad I could help. \$\endgroup\$
    – danijar
    Nov 21, 2013 at 17:09

1 Answer 1

2
\$\begingroup\$

Don't move the player's position directly in response to keyboard input. Instead always move the player forward relative to the direction it's facing, and lerp to different rotations based on keyboard input.

\$\endgroup\$

You must log in to answer this question.

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