- Home /
Question by
dmfx9 · May 11, 2020 at 03:54 PM ·
animatorfpscharactercontrollerfps controller
why has the animator component stopped my scripts working?
I'm making a fps and have my player setup with a character controller script and a view script attached to the camera which is a child of the player which was all working fine. then i added an animator to the player and for some reason now i can no longer move and look around at the same time. does anyone have any idea what is causing this here are the scripts I'm using.
player controller [SerializeField] private float speed;
[SerializeField]
private CharacterController characterController;
private Vector3 moveD;
// Start is called before the first frame update
void Start()
{
characterController = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
moveD = transform.right * x + transform.forward * z;
characterController.Move(moveD * speed * Time.deltaTime);
}
}
camera controller
[SerializeField]
private float viewSpeed;
private float xRotation;
[SerializeField]
private Transform playerBody;
// Start is called before the first frame update
void Start()
{
//locks the cursor away from view
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
//gets mouse x and y rotation
float mouseX = Input.GetAxis("Mouse X") * viewSpeed * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * viewSpeed * Time.deltaTime;
//converts mouse input to float for rotation view
xRotation -= mouseY;
//stops camera rotating up or down over 90 degrees
xRotation = Mathf.Clamp(xRotation, -58, 58);
//rotates the player around the y axis and look up and down on the y axis
playerBody.Rotate(Vector3.up * mouseX);
transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
}
}
Comment