Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Vire · Jan 29, 2014 at 02:56 AM · cameracamera rotaterotatearoundclamped rotation

Clamp Camera Angle not Working

Hi there, I am trying to clamp my camera angle and have looked at various topics here but can't work out why it jitters while rotating on specific angles. I have some ideas, but even so I'm not sure how to fix it.

For example - If my camera is directly behind my character and I raise it up over his head, it clamps perfectly, same with under the character, but if it's been rotated horizontally around the character the camera jitters horribly when I try to move it vertically.

This is the code I'm using:

 void FreeCamera(float mh, float mv)
 {
     float rotationAmount;
     float rotationHAmount;

     if(((mh > deadZone || mh < -deadZone)) || (mh > deadZone || mh < -deadZone))
     {
         rotationHAmount = mh * hRotateSpeed * Time.deltaTime;
         camera.transform.RotateAround(target.transform.position, Vector3.up, rotationHAmount);
     }
     if(((mv > deadZone || mv < -deadZone)) || (mv > deadZone || mv < -deadZone))
     {
         rotationAmount = mv * -1.0f * vRotateSpeed * Time.deltaTime;
         Vector3 currentVector = transform.position - target.transform.position;
         float angleBetween = Vector3.Angle(initialVector, currentVector) * (Vector3.Cross(initialVector, currentVector).x > 0 ? 1 : -1);
         float newAngle = Mathf.Clamp(angleBetween + rotationAmount, -maxAngle, maxAngle);
         rotationAmount = newAngle - angleBetween;

         camera.transform.RotateAround(target.transform.position, cam.transform.right, rotationAmount);
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by frogsbo · Jan 29, 2014 at 05:15 AM

new angle variable is being clamped, but then you are adding an extra variable that will make the camera turn extra.

clamp the entire variable of the rotation without adding one after

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vire · Jan 29, 2014 at 06:03 AM 0
Share

Don't quite understand what you're saying to do.. What variable is making the camera turn more? What is the 'one after' that I'm not meant to add, the rotationAmount = newAngle - angleBetween; ?

avatar image Vire · Jan 31, 2014 at 04:01 AM 0
Share

Does anyone know what frogsbo means? I still can't figure it out.

avatar image
0

Answer by Beks_Omega · Jul 06, 2017 at 08:37 PM

For anyone that finds this in the future here are some links on how to clamp it for the horizontal direction:

http://answers.unity3d.com/questions/400822/rotatearound-clamp-not-working.html

http://answers.unity3d.com/questions/438836/limit-camera-rotation-with-rotatearound.html

And here are some for the vertical direction:

https://stackoverflow.com/questions/44837086/how-to-limit-clamp-y-axis-rotation-for-transform-rotatearound-unity

http://answers.unity3d.com/questions/438836/limit-camera-rotation-with-rotatearound.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Math.f Clamp this 0 Answers

Limit Y Axis transform.RotateAround 1 Answer

Clamping position of camera when using RotateAround? 0 Answers

I can't figure out how to clamp it 2 Answers

Clamping RotateAround 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges