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

Bad LAG with transform.Translate

Discussion in 'Scripting' started by felixwcf, Sep 27, 2012.

  1. felixwcf

    felixwcf

    Joined:
    May 22, 2012
    Posts:
    16
    I'm doing a racing game, the road keep generated and Translate, camera still. Road will moving until a certain point, out of camera view, the road will be destroyed.

    The script is
    Code (csharp):
    1. function Update () {
    2.    
    3.     gameObject.transform.Translate(0, 0, -30, Space.World);
    4. }
    Just like this! but when I run the game in the iPhone simulator, the game is noticeably laggish (a bit jumpy)

    Is it because i'm using the Update function? Please advice...
    If I add some low-poly cars(obstacles), it is worse.

    No draw calls no polygon draw problem. My road is made of a cube and simple texture! My FPS Count is around >150.
     
    Last edited: Sep 27, 2012
    Harlody likes this.
  2. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    You don't exactly give much to go on, but Update is executed every frame and the frame rate is not constant, meaning the speed of your objects as a result will not be constant either.

    To correct this, scale your speed with Time.deltaTime. Delta time is the time between this frame and the one before it, so if you scale speed by it, the result will be that your speed is in units per second.
     
  3. felixwcf

    felixwcf

    Joined:
    May 22, 2012
    Posts:
    16
    Actually I'm Unity banana and yeah I just learned that the Update frame rate is not constant. Actually I do use Time.deltaTime on my Translate script, the problem is still noticeably exist. It becomes better after I switched the game quality to simple, and shut down the vSync. Thank you. I will pay more attention to this part in other scrips as well.