Hi to all!
I have a simple question about how rotate the character to face his movement direction.
It’s a isometric project that uses CharacterController.Move script reference to move the player.
Ps.: is NOT a click-to-move or mouse pointer direction like most Survival-games, just a simple WASD/Joystick Axis based, and the camera is fixed too.
public class ExampleClass : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
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);
}
}
How can I implement the rotation on Y-axis in this case and make the character face his direction??
Thanks for the attention!