public class Controller : MonoBehaviour { // Made by HEWKEW public float speed = 4; private CharacterController controller; private void Start() { //We need a controller. This will let us access to very useful functions. controller = GetComponent(); } private void Update() { //We start our functions and keep them running. Move(); Rotate(); } private void Move() { //We need a Vector3 to storage our input horizontal for our x axis and vertical for our z axis. The y axis //Is not needed because we won't move our object vertically. Vector3 movement = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); //Since movement has inputs with maximun 1 and minimun -1, we multiply it to our speed. For example: //Speed: 4 ==> Movement (1, 0, or -1) * Speed = (4, 0, -4) controller.SimpleMove(speed * movement); } private void Rotate() { //Ray from the main camera to the mouse position. Ray _ray = Camera.main.ScreenPointToRay(Input.mousePosition); //New plane (not a real plane) to get the raycast. Plane _plane = new Plane(Vector3.up, Vector3.zero); //Distance from the center of the plane to the raycast (position 0 + distance from it to the hit) float distance; if(_plane.Raycast(_ray, out distance)) { //We wont need to rotate our character to look to the ground. So we need a new Vector3 to ignore it. Vector3 point = new Vector3(_ray.GetPoint(distance).x, transform.position.y, _ray.GetPoint(distance).z); //Then, we look at that point. transform.LookAt(point); } } }