Jump to content
  • Advertisement
Sign in to follow this  
anupgupta

Unity Camera Clamp Rotation

This topic is 1559 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
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. 

Edited by HappyCoder

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!