Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Jerky / Stuttering transform

Discussion in 'Scripting' started by akitsu, Feb 18, 2014.

  1. akitsu

    akitsu

    Joined:
    Nov 26, 2013
    Posts:
    38
    Hello!

    I have problem to get smooth movement with transform. I have tried all kind of things past 3 months to fix this issue. I know pretty much problem is with deltaTime as I have read others have same kind of problems, but have no found solution for this problem. Here is one of codes I have used

    using UnityEngine;
    using System;

    public class Move : MonoBehaviour
    {
    public float speed;

    void Update()
    {
    transform.position -= Vector3.right * (speed * Time.deltaTime);
    }
    }


    So this is so very basic script that should work, but I see much jerkiness / stuttering on Android, PC and etc. Have also tried to cap framerate and so on. So if anyone know the solution for this problem please tell me! I am already thinking going back to code with Libgdx as I can't get so easy thing to work with Unity. Thanks for your replies already!
     
  2. SiegfriedCroes

    SiegfriedCroes

    Joined:
    Oct 19, 2013
    Posts:
    569
    What happens when you don't use deltaTime?
     
  3. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    For smooth movement you should use Vector3.Lerp() method - http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html

    Code (csharp):
    1.  
    2. public class Move : MonoBehaviour
    3. {
    4.    public float speed;
    5.    void Update()
    6.    {
    7.       transform.position = Vector3.Lerp(transform.position, Vector3.right, Time.deltaTime * speed);
    8.    }
    9. }
    10.  
     
  4. akitsu

    akitsu

    Joined:
    Nov 26, 2013
    Posts:
    38
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Can you reproduce it in an empty project or does it only happen in your actual project? If you could also show a screenshot of you Unity windows including the hierarchy and so on may help.
     
  6. akitsu

    akitsu

    Joined:
    Nov 26, 2013
    Posts:
    38
    I have tried many times with empty project. Only in scene is cube with script and camera. Still I'm seeing the lag
     
  7. jackmott

    jackmott

    Joined:
    Jan 5, 2014
    Posts:
    167
    I would expect somewhere in your code you are doing an expensive/slow computation that sometimes takes more than a frame to complete.
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Could you make a video showing the issue?
     
  9. akitsu

    akitsu

    Joined:
    Nov 26, 2013
    Posts:
    38
    I'm mainly trying with Android as we are making / publishing game for it! We have tried many tablets / phones with single cube. I think I could make Android build if needed!
     
  10. Deleted User

    Deleted User

    Guest

    is your camera stationary or does it move or follows the cube? If its following than try to update your camera position inside LateUpdate()
     
  11. akitsu

    akitsu

    Joined:
    Nov 26, 2013
    Posts:
    38
    The camera is stationary