Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 ChadrickEvans · Feb 13, 2018 at 01:24 AM · camerarigidbodyvelocityjitterlateupdate

Is my (LateUpdate) camera + rigidbody causing jitter?

I've been updating an old camera script to use SmoothDamp instead of Lerp but something interesting came up. It seems there's a bit of jittering involved in all of the scenes using this script. At first I thought I may have accidentally altered the rigidbody movement script so I made a parented test. I'm certain the camera script is causing the jitter. With a "smoothTime" value of 0f the camera is tight with no noticeable jitter, however, simply bumping this up to 0.1f creates an issue.

I'll also provide the guts of the rigidbody movement code and the camera script. I have been using variations of these scripts for months and I've never had an issue so this definitely caught me by surprise. Could it be a timestep issue or is this entirely script-based?


My Rigidbody movement script:

     Vector3 refMove;
     Vector3 refV;
     Vector3 refH;
 
     void FixedUpdate(){
         refV = Camera.main.transform.TransformDirection(Vector3.forward);
         refH = new Vector3(refV.z, 0, -refV.x);
         refV.y = 0;
 
         refMove = (((Input.GetAxis("Horizontal") * speed) * refH.normalized) + 
             ((Input.GetAxis("Vertical") * speed) * refV.normalized));
 
         rg.velocity = AffectVelocity();
     }
 
     Vector3 newVelocity;
 
     public Vector3 AffectVelocity(){
         newVelocity = rg.velocity;
 
         if(Paused){ 
             newVelocity.x = 0f;
             newVelocity.z = 0f;
             return newVelocity; 
         }
 
         newVelocity.x = (refMove.x * speed);
         newVelocity.z = (refMove.z * speed);
 
         return newVelocity;
     }



My camera script:

     Vector3 camPosition;

     void LateUpdate () {
         camPosition.x = Mathf.Clamp(target.position.x + Xoffset, StopLeft_Map, StopRight_Map);
         camPosition.y = target.position.y + Yoffset;
         camPosition.z = target.position.z+ zoomDist;
 
         transform.position = Vector3.SmoothDamp(transform.position, camPosition, ref _velocity, 
             _smooth);
 
     }



The "target" is simply a reference to the object with the rigidbody on it. Also, I have experimented with switching the camera transform code to FixedUpdate and Update. Nothing seems to be working.

Comment
Add comment · Show 1
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 Buckslice · Feb 13, 2018 at 02:01 AM 0
Share

I tried your code in a fresh project and I got it to move smoothly when the camera code was in FixedUpdate() ins$$anonymous$$d. I also changed your cam code to just use Vector3.Lerp ins$$anonymous$$d of SmoothDamp because I wasn't sure what the other variables were supposed to be. So maybe something else in your code is affecting it?

2 Replies

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

Answer by ChadrickEvans · Feb 13, 2018 at 04:23 PM

I managed to get this fixed by changing two things. (Although this may not be the case for everyone I wanted to share my results).

In the camera script, Instead of setting the target to to the actual gameobject's transform.position I set it to the Rigidbody.position


     camPosition.x = Mathf.Clamp(target.rigidbody.position.x + Xoffset, StopLeft_Map, StopRight_Map);
     camPosition.y = target.rigidbody.position.y + Yoffset;
     camPosition.z = ZPush + zoomDist;


Then, I changed the interpolation mode to extrapolate on the target rigidbody. Runs as smooth as it did before!

Again, this might not fix the issue for everybody but it was a great workaround for me.

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 devondyer · Feb 13, 2018 at 02:22 AM

Try calculating the camera's position in the void Update() function of the Camera Script, rather than trying to calculate its next position at the same time as moving the camera.

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 ChadrickEvans · Feb 13, 2018 at 10:58 AM 0
Share

This was one of the ideas I originally tried but it didn't seem to work.

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

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

Get Interpolated rigidbody velocity 1 Answer

Jitter on Object with Rigidbody 0 Answers

Update/Late Update jitter problem(non FixedUpdate related) 1 Answer

Moving a camera with AddFoce, or setting velocity, need help 1 Answer

Jittery Rigidbody 4 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