Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 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 lucky3d1 · Jul 22, 2015 at 02:45 PM · cameravelocityjitterstuttermoveposition

Camera Jitter / Stutter

Hi!

Is it possible to use Rigidbody.MovePosition instead of velocity to move a character followed by the camera without any stutter / choppiness? I've been searching for days :-(

Exactly the same problem as here:

http://answers.unity3d.com/questions/931654/synchronise-translation-with-physics.html#comment-1012178

Enabling 'interpolate' fix half of the stutter: 'While interpolation, horizontal translation in FixedUpdate and LateUpdate completely fixes the jitter on y axis, both on player and the scene, they introduce jitter on the x axis. '

Setting the velocity fix the problem but this is discouraged because it may break the physic, so i'd prefer avoiding it. http://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html

The project is 3d platformer, with lot of fast movement, run, jump, so stutter is really important.

Thanks! This forum is a really strong help.

Comment
Add comment · Show 11
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 lucky3d1 · Jul 22, 2015 at 03:21 PM 0
Share

Thanks alexi but the camera already moves in LateUpdate, no parenting. As said above it's the same situation as here: http://answers.unity3d.com/questions/931654/synchronise-translation-with-physics.html#comment-1012178

avatar image lucky3d1 · Jul 22, 2015 at 03:34 PM 0
Share

The camera LookAt the player, but even when slerping the rotation or lerping the position to have smooth movement, either the player or the background slightly stutter (this is more visible in fullscreen resolution).

avatar image meat5000 ♦ · Jul 22, 2015 at 04:21 PM 0
Share

Is your camera following behind your player and angled slightly downwards?

avatar image lucky3d1 · Jul 22, 2015 at 04:36 PM 0
Share

Both back tracking and free mode were tested. Yes camera height > player position.

avatar image meat5000 ♦ · Jul 22, 2015 at 04:39 PM 0
Share

Post the code that deals with camera height. The downward angle part of my inquiry was important by the way :P

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by alexi123454 · Jul 22, 2015 at 03:04 PM

Instead of parenting the camera directly to the character, why not make the camera interpolate towards the character's position over time? This would smooth out the camera movements and remove the stutter from the visuals.

If you set the lerp speed to be fairly high, then the position of the camera should be pretty similar to before as well.

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
1

Answer by meat5000 · Jul 26, 2015 at 07:47 PM

I tried your script and it seems to work fine for me changing LateUpdate to FixedUpdate. The difference between the deltaTime calculated values in the camerascript and the fixedupdate-updated values of the player causes a small oscillation around the maximum distance point, which is basically your object jitter. You can see this when you Debug.Log the distance. In FixedUpdate this value becomes pretty fixed when moving.

If you really really want to use Update() or LateUpdate() you can try this:

Make a timer in FixedUpdate which records the total fixedDeltaTime passed since the code had last run in Update. Use this variable instead of Time.deltaTime in the code and reset the timer when you are done with the data.

This should help sync up the number of steps calculated for the player with the steps moved by the camera.

 void Update()
 {
     Vector3 camForwardZ = transform.forward;
     camForwardZ.y = 0.0f;        
      
     float currentDistance = Vector3.Distance (transform.position, player.position);            
  
     transform.position = transform.position + ((camForwardZ * (currentDistance - distance_max)) * 3f * timer);            
     transform.position = new Vector3(transform.position.x,  transform.position.y + ((player.position.y + height) - transform.position.y)*timer*2f , transform.position.z); 
     transform.LookAt (player.position);        

     ResetTimer();
 }    
      
 float timer = 0.0f;
     
 void ResetTimer()
 {
     timer = 0.0f;
 }
 void FixedUpdate()
 {
     timer += Time.fixedDeltaTime;
 }




Comment
Add comment · Show 6 · 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 lucky3d1 · Jul 27, 2015 at 01:06 PM 0
Share

I tried your script and it seems to work fine for me changing LateUpdate to FixedUpdate

Thanks for your input meat5000. But that's strange, i still got the stutters when using FixedUpdate (tested on two computers, nvidia and ati cards). I tried your script too. Have you checked it doesn't stutter when building the game?

Anyway I got tired of this and i've switched my player physic to Character Controller, moving in update(), loosing the benefits of a rigid body physics, but the camera doesn't stutter now. Looks like it's inherent to the FixedUpdate behaviour.

avatar image meat5000 ♦ · Jul 27, 2015 at 01:49 PM 0
Share

I made a basic setup, Player script on a cube and camera1 on Camera, of course, with a terrain.

I was able to reduce error in many many ways but only using FixedUpdate ti$$anonymous$$g completely removed all jitter.

To see it visually I used Shift-F on camera or player in scene view and scroll out. You can see all jitter then. Also it was most apparent when you move your player far out to get the camera straight on then move the player back in to the camera. The biggest sign was the very constant figure I get in Debug.Log on Distance from player to camera while moving at full speed (when distance has reached its limit). If there is no jitter that figure will not budge. Any deviation of that figure is an indication of further ti$$anonymous$$g issues.

Tried Standalone. No jitter.

What are your framerates, FixedTimeStep and $$anonymous$$axAllowedTimeStep values? Do you have a heavy physics routine? If you turn iteration count to 1 (temporarily!) does the jitter go away?

Put a little Debug.Log("I$$anonymous$$ FIRING!!") in Update and a slightly different one in FixedUpdate and see how many FU's you get per U.

avatar image lucky3d1 · Jul 27, 2015 at 02:29 PM 0
Share

I made a basic setup, Player script on a cube and camera1 on Camera, of course, with a terrain.

Same here, with a few colored cubes in the background for a better visualisation of the jitter.

The physics and time parameters are the defaults ones: Sleep: 0.005 Default contact offset: 0.01 Solver iter: 6 (no difference if set it to 1)

Fixed timestep: 0.02 $$anonymous$$aximum allowed: 0.333 Time scale: 1

FPS: 90 average, but it's strange i've seen it ten time higher before (edit: hum maybe because i'm testing on an old ati card right now, my other nvidia card is stronger)

Put a little Debug.Log("I$$anonymous$$ FIRING!!") in Update and a slightly different one in FixedUpdate and see how many FU's you get per U.

I'm not sure to understand what you mean here, but after a few seconds i get 335 log in FU and 392 in U.

avatar image meat5000 ♦ · Jul 27, 2015 at 02:58 PM 0
Share

That looks the same as my firing rates.

I built for android. It doesnt stutter but movement doesnt look very clean.

Also I notice that the camera likes to glitch out when crossing 90 degree points. You can occasionally see this in editor. I think its because of the line

transform.position = transform.position + ((camForwardZ * (currentDistance - distance_max)) * 3f * timer);

with the way the distance is handled.

If you have added other code to the scripts experiment with moving timer += Time.fixedDeltaTime; around the function (start or end) and try the Reset() call at different points (immediately after data usage or at the end of Update) etc.

avatar image finnrayment · Oct 13, 2016 at 09:54 AM 0
Share

Holy crap, this actually fixed my problem! Thanks so much!

avatar image b1gry4n finnrayment · Oct 13, 2016 at 12:18 PM 0
Share

Just to be clear, the stutter happens when you are updating the "target" in fixed update and updating the camera in update. Fixed update happens at fixed intervals, update does not. The fix is to change your camera follow update method to be the same as your targets update method.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I fix Camera stuttering in first person? 1 Answer

Is my (LateUpdate) camera + rigidbody causing jitter? 2 Answers

Camera Rotate behind rotating ball 1 Answer

Why is 2d camera not smooth at 30 FPS 0 Answers

Auto-Center 3rd person camera, problem when moving towards the camera 0 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