I have a script that’s supposed to align the player with the camera whenever you move. here’s my script.
//Return direction align with Camera
Vector3 targetDirection
{
get
{
Vector3; cameraForward = mainCamera.TransformDirection(Vector3.forward);
cameraForward.y = 0; //set to 0 because of camera rotation on the X axis
//get the right-facing direction of the camera
Vector3; cameraRight = mainCamera.TransformDirection(Vector3.right);
//determine the direction the player will face based on input and the camera's right and forward directions
return Input.GetAxis("Horizontal") * cameraRight + Input.GetAxis("Vertical") * cameraForward;
}
}
//This method needs to run on Update
void RotateWhileMoving()
{
if(speed > 0.5f)
{
//normalize the direction the player should face
Vector3; lookDirection = targetDirection.normalized;
//rotate the player to face the correct direction ONLY if there is any player input
if (lookDirection != Vector3.zero)
{
newRotation = Quaternion.LookRotation(lookDirection);
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, 4.5f * Time.deltaTime);
}
}
}
But I keep getting these errors
How do I fix these?
