Search Unity

GameObject Movement Stuttering

Discussion in 'General Graphics' started by IndiumIndeed, Jul 8, 2015.

?

Do you have the same stuttering problem?

  1. Yes

    15 vote(s)
    83.3%
  2. No

    3 vote(s)
    16.7%
  1. IndiumIndeed

    IndiumIndeed

    Joined:
    Jun 17, 2014
    Posts:
    6
    I have a major problem with stuttering of movement with all GameObject.
    • The framerate seems to be fine: from 35 to 70 fps.
    • The stuttering happens both in Unity editor (fast computer) and when testing with any of my 3 Android test devices.
    • I measured the change per frame for transform.position.y/Time.deltaTime and it seems to be very much constant.
    • I have tried different sizes of sprites. I have tried sprites with width and height 2^X and 2^Y, where X and Y are constants.
    • I tried with sprites and 3D objects.
    I have tried moving the GameObjects with the following ways:
    • transform.position=new Vector3(transform.position.x, transform.position.y+Time.deltaTime*speed, transform.position.z);
    • Adding a kinematic RigidBody2D to the GameObject and setting constant speed.
    • Making linear movement animation.
    All of these result to the same stuttering problem.

    I attached a simplified test project to this message.
    I have tried Unity 5.1.1f1 and 4.6.7f1.

    Could someone, please, test if they have the same problem?
     
    Last edited: Jul 8, 2015
  2. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,837
    It is a good idea to also use Lerp for moving objects. It causes the object to mathematically reach its destination very smoothly.

    Here is an example:
    Code (csharp):
    1.  
    2. void Update()
    3. {
    4. Vector3 newPosition = new Vector3(transform.position.x, newYPosition, transform.position.z);
    5. transform.position = Vector3.Lerp( transform.position,  newPosition, speed * Time.deltaTIme);
    6. }
    7.  
    you are determining the new position that the object needs to be sometime in your code/
    You are constantly lerping the transform's current position to the new position.
    Every update, the object gets closer and closer to its final destination.
    This allows a smooth position change
    It's important to remember that the object position might never reach the target position, so you need to remember that mathematically it never really reaches it's final destination, but it will be very close (ex: 0.001).

    Also, if your just starting a game and only getting 35 FPS, then something is definitely wrong with your code. You are probably doing things in update you shouldn't. Can you post your update routine?
     
    Last edited: Jul 9, 2015