My character is not rotating with the camera

Hi everyone,

I’ve decided to remake my first-person character controller. It was handled with a rigidbody but now I want to see what I can achieve with a Character Controller. I have two scripts attached to my player’s body, one for the movement and the other for the camera movement. The camera is a child object of the player’s body. My problem is that I can rotate the camera but the player’s body won’t rotate with it on the x-axis.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class View : MonoBehaviour
{
    public float sensitivity;
    public Transform playerCamera;
    float limit;
    public CharacterController controller;
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        float movementX = Input.GetAxis("Mouse X") * sensitivity;
        float movementY = Input.GetAxis("Mouse Y") * -sensitivity;

        limit -= movementY;
        limit = Mathf.Clamp(limit, -90f, 90f);

        transform.Rotate(0, movementX, 0);
        playerCamera.transform.localRotation = Quaternion.Euler(-limit, 0, 0);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public CharacterController controller;
    float playerSpeed = 2.0f;
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        PlayerInput();
    }

    void PlayerInput()
    {
        Vector3 move = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        move.Normalize();

        controller.Move(move * Time.deltaTime * playerSpeed);
    }
}

Does anyone know what the problem is ?

Thanks in advance,
draavv.

Small edit : I did some research and see a lot of people using Cinemachine with a Character Controller. Is it any good?

I’ve only toyed with cinemachine a little bit, but that does seem to be the way to go these days. This year Unity (FINALLY) got a new FPS example you could play with to see their implementation. It has FPS and 3rd person and uses cinemachine for the camera.

1 Like

Nice thanks a bunch for the insight!

1 Like