Hi all! I’m working on a game where you click to move the player. There’s so many ways to do this, but I decided to use the Move method and character controller to prevent my character from going through walls(and for the sake of detecting walls). Well, I think it is because the nature of the Move that I found it difficult myself to rotate the player.
I’m trying to make the player rotate to the direction it’s moving whenever the mouse button is clicked. Does anyone know how I can do this? Would I have to use another move method and detect collision through code?
Control.cs
void Start(){
controller = GetComponent<CharacterController> ();
}
void FixedUpdate () {
UpdateMovement ();
}
void UpdateMovement(){
RaycastHit hit = new RaycastHit ();
if (Input.GetButtonDown ("Movement") && canMove) {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit))
target = new Vector3 (hit.point.x, characterHeight, hit.point.z);
}
if (Vector3.Magnitude (target - transform.position) > 0.3f) {
if (controller.isGrounded) {
moveDirection = (target - transform.position).normalized;
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= moveSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
} else
transform.position = target;
waypoint.position = target;
}