• 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 sysameca · Mar 29, 2015 at 07:16 AM · camerarenderingupdatejitterlateupdate

Update/Late Update jitter problem(non FixedUpdate related)

Hey guys i am experiencing an issue where an object placed on the scene follows the main camera and jitters if the camera moves in the LateUpdate() method. The way i understood is late update gets called once per frame after Update() is finished, so there should be really no problem moving the object like that. The way i created the scene:

  1. Create a new empty scene.

  2. Set the camera to orthographic and attach this script to it:

      public class CameraMoverTest : MonoBehaviour
       {
         private void Update()
         {
             transform.position += new Vector3(1, 0, 0) * Time.deltaTime * 20;
             Debug.Log("Camera Position X: " + transform.position.x);
         }
     
         //// Jitters
         //private void LateUpdate()
         //{
         //    transform.position += new Vector3(1, 0, 0) * Time.deltaTime * 20;
         //    Debug.Log("Camera Position X: " + transform.position.x); 
         //}
      }
    
    

    3.Create a new game object, add SpriteRenderer component and add some sprite to visualize the jitter and add this script to the same game object:

     public class MovedObjectTest : MonoBehaviour
     {
         private Vector2 m_initialPosition;
     
         private void Start()
         {
             m_initialPosition = Camera.main.transform.position;
         }
     
         private void Update()
         {
             Vector3 position = Camera.main.transform.position;
             position.z = 0;
             transform.position = position;
     
             Debug.Log("Object Position X: " + transform.position.x);
         }
     }
     
    

So the object does not jitter if the camera moves in the Update() method, but if you uncomment the LateUpdate() method and comment the Update() you will see a noticeable jittery movement over the X axis of the moving object. Both debug logs shows exactly the same camera and object positions. I can't really see where the problem is. What am i doing wrong? Please explain.

EDIT: So i did some test and came up with some observations. It seems its something to do with the order of execution.

Observation 1

Moved Object - Updating Method : LateUpdate()

Camera - Updating Method : LateUpdate()

Result: Jitter

Observation 2

Moved Object - Updating Method : LateUpdate()

Camera - Updating Method : Update()

Result: NO Jitter

Observation 3

Moved Object - Updating Method : Update()

Camera - Updating Method : Update()

Result: Jitter

Observation 4

Moved Object - Updating Method : Update()

Camera - Updating Method : LateUpdate()

Result: NO Jitter

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
2

Answer by Nanity · Mar 29, 2015 at 08:46 AM

Option #4 is the correct execution. See http://docs.unity3d.com/ScriptReference/MonoBehaviour.LateUpdate.html

In Options #1 and #3 you need to take care of the script execution order. Generally a bad advice to rely on this. http://docs.unity3d.com/Manual/class-ScriptExecution.html

Option #2 basically is the same as #4, but either the camera or the object is behind one frame regarding the movement.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 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

Related Questions

Stacked cameras not working after update 2018.3 -> 2019.2 0 Answers

How can I get my camera to momentarily pause between different positions when using lerp? 0 Answers

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

Random Camera Jitter 1 Answer

Need some help with portal rendering 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges