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. Dismiss Notice

Is this a BUG in Unity? Floating point + FixedUpdate() problem

Discussion in 'Scripting' started by NecroToad, Oct 27, 2014.

  1. NecroToad

    NecroToad

    Joined:
    Oct 27, 2014
    Posts:
    8
    Hi,

    I'm experiencing a problem with the physics components in my game. In fact, every physics component that i made in my life have this problem, regardless of project, so maybe there's any concept about Unity that i'm not understanding?

    Imagine that i have a float called "speed" and i want it to be added on my character's position on every update. After doing this, i realize that the movement of my character isn't uniform, some times it's faster and sometimes it is slower.
    Than i found out that it's because i can't put it on Update(), i have to put it on FixedUpdate(), because Update is relative to the framerate of my game. But the problem is, even using FixedUpdate() the speed is unstable, it is more stable than using Update(), but it still isn't right. Some times the jump of my character is longer or faster than other times.
    I'm sure that isn't a bug on my code, because it happens even in very simple implementations such as in the example cited above about a float variable "speed" being added to an object's position.exato

    I'm understanding that as i'm using FixedUpdate() I don't need to use Time.delta. So am I doing it right? Maybe it is a problem with the Vsync property of my Project Settings?

    Thanks!
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Afaik, if you're not using any physics-related methods like AddForce, you should still multiply by Time.deltaTime in FixedUpdate.
     
  3. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
    Without seeing your code I can't be certain. If you are simply adjusting position each frame, an update method that multiplies by Time.deltatime should be consistent.

    If you are reading input in FixedUpdate, you could run into reliability issues, as well.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    FixedUpdate is only for physics. Use Update for standard movement, along with Time.deltaTime to achieve framerate independence.

    I wouldn't be so sure....

    --Eric