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 EnglishMuffin123 · Dec 01, 2013 at 01:28 AM · camerarotationperformance

Camera Follow Code Causes Jerky Movements

I need a script that will act like the included SmoothFollow.js but will also rotate on the X and Z axes. I messed around with it and came up with this:

 var target : Transform;
 
 var distance = 5.0;
 
 function Update () {
 
     if (!target) {
         return;
     }
         
     wantedRotationAngleY = target.eulerAngles.y;
     currentRotationAngleY = transform.eulerAngles.y;
 
     wantedRotationAngleX = target.eulerAngles.x;
     currentRotationAngleX = transform.eulerAngles.x;
 
 
     currentRotationAngleY = Mathf.LerpAngle(currentRotationAngleY, wantedRotationAngleY, Time.deltaTime);    
     currentRotationAngleX = Mathf.LerpAngle(currentRotationAngleX, wantedRotationAngleX, Time.deltaTime);
 
     
     currentRotation = Quaternion.Euler(currentRotationAngleX, currentRotationAngleY, 0);
 
 
     transform.position = target.position;
     transform.position -= currentRotation * Vector3.forward * distance;
 
     transform.localEulerAngles = target.transform.localEulerAngles;
 
 }

The script shown above does its intended job perfectly however it is extremely jerky when rotating especially on X axis rotation. Is there a way to better write this script or a way to smooth it? Once this is fixed I will be applying dampening so making the camera a child is not an option. Thank you.

Comment
Add comment · Show 2
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 MrProfessorTroll · Dec 01, 2013 at 02:09 AM 0
Share

You need to switch the movement part and the camera follow areas of the code. You must move the player then make the camera follow. That will eli$$anonymous$$ate the jerky movement

avatar image EnglishMuffin123 · Dec 01, 2013 at 07:31 AM 0
Share

I switched the transform.localEulerAngles and the transform.position in code so the angle changes before the position since that's all I can assume you mean and that fixed everything. Thanks! That comment is an accepted answer.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by EnglishMuffin123 · Dec 01, 2013 at 08:16 AM

To anyone looking for a script like this, MrProffesorTroll has fixed it. Please read the comments under the question for an explanation but here is the completed code without dampening added:

 var target : Transform;
 
 var distance = 5.0;
 
 function FixedUpdate () {
 
     if (!target) {
         return;
     }
         
     wantedRotationAngleY = target.eulerAngles.y;
     currentRotationAngleY = transform.eulerAngles.y;
     
     wantedRotationAngleX = target.eulerAngles.x;
     currentRotationAngleX = transform.eulerAngles.x;
 
 
     currentRotationAngleY = Mathf.LerpAngle(currentRotationAngleY, wantedRotationAngleY, Time.deltaTime);    
     currentRotationAngleX = Mathf.LerpAngle(currentRotationAngleX, wantedRotationAngleX, Time.deltaTime);
 
     
     currentRotation = Quaternion.Euler(currentRotationAngleX, currentRotationAngleY, 0);
 
 
     transform.localEulerAngles = target.transform.localEulerAngles;
 
     transform.position = target.position;
     transform.position -= currentRotation * Vector3.forward * distance;
 
 }
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
avatar image
0

Answer by Dean432 · Dec 07, 2013 at 12:40 AM

I don't know if anyone has noticed this but if you get jerky movements with the follow transform script from the mobile assets, i found a way to stop it jerking but its not a fix, i was fiddling around trying to find out what made the character so jerky and found that is was the follow transform script on the camera pivot, though if you run the game and turn the script off and on again in the inspector while the game is still running, it thens runs perfectly smooth like in previous versions of unity, if this helps anyone with fixing the script that would be great.

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

18 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

Related Questions

How to make the camera rotate only when right click is held down on the mouse? 1 Answer

character view range 2 Answers

Unity automatically rotate camera on slopes up/down 0 Answers

Player making a 360° looping, camera not following 0 Answers

How would you set a camera lerp position with code not a child object? 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