Camera Clamp Rotation

Started by
0 comments, last by HappyCoder 9 years, 10 months ago

i have written a camera script in Unity3D to rotate on swipe in left, right, up or down direction and then slow down gradually.
and my camera is looking at the car..while rotating rotating around it.

the only thing i was doing is to clamp the value of the camera rotation when the user swiped up or down..because i don't want the camera to go above the car or under the car while rotating.

i tried this code for clamping..but in vain

Vector3objRot = cachedTransform.rotation.eulerAngles;
float clampValue = Mathf.Clamp(objRot.x, 20, 50);

cachedTransform.rotation.eulerAngles.Set(clampValue, objRot.y, objRot.z);

am attaching my camera script..if you guys could help me out to figure it out.
Any suggestion Please.

[attachment=22207:CameraScript.txt]

Advertisement

Try this


Vector3 objRot = cachedTransform.eulerAngles;
objRot.x = Mathf.Clamp(objRot.x, 20, 50);

cachedTransform.eulerAngles = objRot;

The documentation says not to set individual values

http://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html

Also, you shouldn't put cachedTransform.rotation.eulerAngles. You can modify the transform directly using cachedTransform.eulerAngles.

My current game project Platform RPG

This topic is closed to new replies.

Advertisement