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);
}
GetAxis
method should take the desired axis as string parameter. \$\endgroup\$ – danijar Nov 21 '13 at 7:19