Sign in to follow this  

Unity Camera Clamp Rotation

This topic is 1273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Edited by anupgupta

Share this post


Link to post
Share on other sites

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. 

Edited by HappyCoder

Share this post


Link to post
Share on other sites

This topic is 1273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this