# Rotate camera towards 0 by the angle of an object?

I apologize in advance if my title is unclear. I clamp my horizontal camera rotation upon entering a trigger on a specific object, however this only works if the objects rotation is (0,0,0) which is default. If as an example I duplicate that object and alter its rotation to (0,90,0) and then enter its trigger, my camera will rotate instantly to the value of my clamp (35 degrees in this case).

As far as I can understand from researching this, I need to reset the rotation upon trigger enter and then use that transform as part of an angle which I then add into my Mathf.Clamp. So in my code I use `Vector3 posForward` and then `float lookAngle` to achieve this, but the end result is when I move my mouse right to the x-axis limit, the camera bounces to the left and it just repeats.

`````` // scriptA cameraLook.cs
void Update()
{
Vector2 mouseDelta = Input.GetAxis(xAxis) * Vector2.right + Input.GetAxis(yAxis) * Vector2.up;

rotation.x += mouseDelta.x * mouseSens;
rotation.y += mouseDelta.y * mouseSens;

rotation.y = Mathf.Clamp(rotation.y, -rotLimitY, rotLimitY);

var xQuaternion = Quaternion.AngleAxis(rotation.x, Vector3.up);
var yQuaternion = Quaternion.AngleAxis(rotation.y, Vector3.left);

if (scriptB.isWallRunning) // clamp x-axis movement only inside this if statement
{
// Get the transform.forward upon entering wall trigger
posForward = transform.forward;
posForward.y = 0;
posForward.Normalize();
float lookAngle = Vector3.Angle(Vector3.forward, posForward); // use the angle to adjust clamp

rotation.x = Mathf.Clamp(NormalizeAngle(rotation.x), -rotLimitX + lookAngle, rotLimitX + lookAngle);
}

transform.localRotation = Quaternion;
player.transform.rotation = Quaternion;
}

public static float NormalizeAngle(float angle)
{
angle = (angle + 180) % 360;
if (angle < 0)
{
angle += 360;
}
return angle - 180;
}
``````

Camera stuff is pretty tricky… you may wish to consider using Cinemachine from the Unity Package Manager.

There’s even a dedicated forum: Unity Engine - Unity Discussions

Notes on clamping camera rotation and NOT using .eulerAngles because of gimbal lock:

How to instantly see gimbal lock for yourself:

All about Euler angles and rotations, by StarManta:

https://starmanta.gitbooks.io/unitytipsredux/content/second-question.html