- Home /
Camera shaking on crouching and rotating player
Hello everyone, actually I am having problem with the camera following the player. When the player moves the camera shakes and this effects more when the player is in the crouch position. I am using root motion motion for player with animations by mixamo.
My player script is like this:
Transform cameraT;
void Start () {
cameraT = Camera.main.transform;
}
void FixedUpdate ()
{
float sideMotion = Input.GetAxis("SideMotion");
float straightMotion= Input.GetAxis("StraightMotion");
if (Mathf.Abs(sideMotion) > 0 || Mathf.Abs(straightMotion) > 0)
{
transform.eulerAngles = new Vector3(transform.eulerAngles.x, cameraT.eulerAngles.y);
}
}
Camera Script:
public float distanceFromPlayer=2f;
public float mouseSensitivity=6;
public Transform player;
public Vector2 pitchConstraint= new Vector2(-30,80);
Vector3 rotationSmoothVelocity;
Vector3 currentRotation;
public float rotationSmoothTime = 0.2f;
float yaw; //Rotation around the vertical axis is called yaw
float pitch; //Rotation around the side-to-side axis is called pitch
private void LateUpdate()
{
yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;
pitch = Mathf.Clamp(pitch, pitchConstraint.x, pitchConstraint.y);
currentRotation = Vector3.SmoothDamp
(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
transform.eulerAngles = currentRotation;
transform.position = player.position - transform.forward * distanceFromPlayer;
}
}
For public transform I just Added an empty game object to player chest level and parented it to player. I got few of the rotating camera smoothly trick from an online tutorial, but, that exact thing won't work on player rotation though.
A character controller is attached to player without any rigid body or collider.
Your answer
![](https://koobas.hobune.stream/wayback/20220612114259im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Automatic 3rd person camera 1 Answer
Making object Clamp to Look Rotation of Camera 1 Answer
Rotate character to camera orientation(direction camera is facing) 0 Answers
Camera follow player when player rotates in y-axis 1 Answer
Camera following player gameObject,Camera follows player, with script attached. 1 Answer