Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 pigaroos · Nov 17, 2019 at 11:02 PM · frameratecamera followmagic

The lower the framerate, the more the camera stuttters

Hello everyone! Today I opened a recording program called OBS and it lowered my FPS (understandably). However, I noticed that the camera stutters the lower the framerate (it even happens at 60 FPS, just less noticeably). The script is as follows:

     public Transform target;
 
     public float moveSpeed = 10f;
     public float offset = -1f;
 
     bool startFollowing = false;
 
     // Update is called once per frame
     void LateUpdate()
     {
         float targetYPos = target.position.y - offset;
 
         Vector3 newPosition =
         new Vector3(transform.position.x, targetYPos, transform.position.z);

         //ignore this if statement
         if (startFollowing)
         {
             //this makes the camera follow the player in only the Y axis
             transform.position =
             Vector3.Lerp(transform.position, newPosition, moveSpeed * Time.unscaledDeltaTime);
         }
     }

Would anyone be able to tell me what is wrong with my script? Thank you so much for your time.

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
1
Best Answer

Answer by Ermiq · Nov 18, 2019 at 01:11 PM

I suggest you to read this thread: https://forum.unity.com/threads/camera-stutters-in-a-simple-rotation.389899/
Read carefully what the user rorydriscoll wrote there and try out his lerping method. It works awesome for following camera. Obviously you'll have to modify it to implement into your code because his code is for camera rotation actually but the essential element there is how you set the t parameter in Lerp (source, target, t) functions.
The problem with your code is the more delay between frames (Update() calls), the faster your camera have to move to reach the target position. And by multiplying deltaTime by big numbers (like 10) you make it even more jittery.
With riridriscoll's method you won't need such a big multipliers, it's opposite actually, you'll set less multipliers to make camera follow faster.

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 pigaroos · Nov 18, 2019 at 02:58 PM 0
Share

@Ermiq $$anonymous$$an... that thread was a journey. I ended up in his blog where I tuned a little bit of his (magical) solution into this:

 public Transform target;

 public float moveSpeed = 10f;
 public float offset = -1f;

 bool startFollowing = false;

 // Update is called once per frame
 void LateUpdate()
 {
     float targetYPos = target.position.y - offset;

     Vector3 newPosition =
     new Vector3(transform.position.x, targetYPos, transform.position.z);

     if (startFollowing)
     {
         //this makes the camera follow the player in only the Y axis
         float cameraY =
         Damp(transform.position.y, newPosition.y, 0.0025f, Time.deltaTime);

         transform.position = new Vector3(transform.position.x, cameraY, transform.position.z);
     }
 }

 // Smoothing rate dictates the proportion of source remaining after one second    
 public static float Damp(float source, float target, float smoothing, float dt)
 {
     return $$anonymous$$athf.Lerp(source, target, 1 - $$anonymous$$athf.Pow(smoothing, dt));
 }

That worked perfectly. Thank you so much for setting me on the right path!

avatar image
0

Answer by suIly · Nov 18, 2019 at 03:14 PM

You should use FixedUpdate instead of LateUpdate.

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

117 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 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 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 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 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 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

Framerate Dependent Mesh Deformation 1 Answer

Accurate Frames Per Second Count 5 Answers

How do I find the frames per second of my game? 6 Answers

How to change framerate for Android? 1 Answer

Parenting Weapon to Empty = Framerate drops to 2fps 2 Answers


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