I'm trying to make a FPP mode in unity where you can see your actual body. I've created a model, rigged everything. My head will rotate to the camera, but i don't want the player to be able to rotate around his body. I've already clamped rotation on x axis, but have problems with clamping around y axis.
void Update () {
currentBodyRotation = body.GetComponent<Transform> ().rotation.eulerAngles.y;
yaw += Input.GetAxis ("Mouse X") * mouseSensitivity;
yawMin = currentBodyRotation - 90f;
yawMax = currentBodyRotation + 90f;
yaw = Mathf.Clamp (yaw, yawMin, yawMax);
pitch -= Input.GetAxis ("Mouse Y") * mouseSensitivity;
pitch = Mathf.Clamp (pitch, pitchMinMax.x, pitchMinMax.y);
currentRotation = Vector3.SmoothDamp (currentRotation, new Vector3 (pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
transform.rotation = Quaternion.Euler (currentRotation);
}
I think rotation has limits when in 0 and 360 angles. My code works perfectly until body hits 360 degrees. When it does though my camera will jerk and just "bounce" off from invisible wall back to the side where it came from.