Question by
stampogamer1 · Nov 29, 2020 at 01:29 AM ·
character controller1st person
1st Person Character Controller X Axis not working
I can move the camera with my mouse up and down, but not left and right. This is the script I'musing PLS HELP.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class mouse_look : MonoBehaviour {
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
Comment
Answer by tradonX · Nov 17, 2021 at 10:27 PM
I think you assignd the variable playerBody to the player and not the parent object. I am guessing you are following brackeys firstperson tutorial. Sorry for bad english.