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 drak8888 · Jan 22, 2013 at 06:12 PM · camerarotationanglesroll

Rotation glitch with camera

So I took the SmoothFollow script for my camera, which works pretty well, and wanted to add some kind of Roll (Z rotation) to the camera when it turns to make it more dynamic.

Most of the time my script works well except at a certain angle where it jumps and turns suddenly to ridiculously high values (like 180 when usually I get angles between 15 and -15). I fixed that by limiting the angles to 15 max both ways but it still jumps to 15 and makes it feel a bit awkward. I suspect this angle is the transition between 360 and 0 but I have no idea how to fix that. Here's the script :

 var target : Transform;
 // The distance in the x-z plane to the target
 var distance = 10.0;
 // the height we want the camera to be above the target
 var height = 5.0;
 // How much we 
 var heightDamping = 2.0;
 var rotationDamping = 3.0;
 var cameraRoll : float;
 
 // Place the script in the Camera-Control group in the component menu
 @script AddComponentMenu("Camera-Control/Smooth Follow")
 
 
 function LateUpdate () {
     
     
     var newheight = height + Input.GetAxis( "Mouse Y" );
     // Early out if we don't have a target
     if (!target)
         return;
     
     // Calculate the current rotation angles
     var wantedRotationAngle = target.eulerAngles.y;
     var wantedHeight = target.position.y + height;
         
     var currentRotationAngle = transform.eulerAngles.y;
     var currentHeight = transform.position.y;
     
     // Damp the rotation around the y-axis
     currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
     
     // Damp the height
     currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
     
     // Convert the angle into a rotation
     var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
     
     // Set the position of the camera on the x-z plane to:
     // distance meters behind the target
     transform.position = target.position;
     transform.position -= currentRotation * Vector3.forward * distance;
 
     // Set the height of the camera
     transform.position.y = currentHeight;
     
     // Always look at the target
     transform.LookAt (target);
     
     var beforeRoll = (wantedRotationAngle - currentRotationAngle)/3; // Takes the values of the camera turning and attenuate them
     
     if(beforeRoll < 15 && beforeRoll > -15 && beforeRoll != 0){ 
         cameraRoll = beforeRoll; // Prevents the angles to go over 15 both way
     }
     
     transform.eulerAngles.z = cameraRoll; // Applies the angle
 }

Does anyone got any idea what to do?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GrnDyRx · Jan 22, 2013 at 09:43 PM

This is just a guess, but I think it may be trying to go from 359.9 to 361.1, which gets bumped down to 15 by the script fix you did, so I would try making something in function update that jumps that for you instead of having unity do it. Just a guess, but my best try.

Comment
Add comment · Show 1 · 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 drak8888 · Jan 22, 2013 at 11:43 PM 0
Share

Actually its when the wanted rotation angle is like at 1 and the current rotation angle is at 359 or so. The $$anonymous$$us then gives something clearly unwanted. I still don't know exactly how to fix that though.

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

10 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

Related Questions

Camera Angle Conflict Pitch & Pan...I'm Lost 1 Answer

Rotation around a moving object. 0 Answers

Determine degrees rotated around an arbitrary axis 0 Answers

Transform Rotation - Maths Problem 2 Answers

Irregular position when instantiating clone during camera rotation? 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