Answer the question
In order to leave comments, you need to log in
How to make a character rotate in the direction of his movement in Unity?
I am new to Unity. I am making an Android game. In the game, the camera is located above the character, and slightly to the side. I made it move (it's made for touch control), but I don't know how to make the character turn in the direction of his movement.
Here is the code I wrote to move it:
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMoveController : MonoBehaviour {
// PUBLIC
public SimpleTouchController leftController;
public float speedMove;
// PRIVATE
private Rigidbody _rigidbody;
[SerializeField] bool continuousRightController = true;
void Awake()
{
_rigidbody = GetComponent<Rigidbody>();
}
public bool ContinuousRightController
{
set{continuousRightController = value;}
}
void FixedUpdate()
{
// move
_rigidbody.MovePosition(transform.position + (transform.forward * leftController.GetTouchPosition.y * Time.deltaTime * speedMove) +
(transform.right * leftController.GetTouchPosition.x * Time.deltaTime * speedMove) );
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question