Search Unity

learning issue "DeltaTime"

Discussion in 'Community Learning & Teaching' started by fares90, Jul 5, 2015.

  1. fares90

    fares90

    Joined:
    May 9, 2015
    Posts:
    3
    hi guys:
    I am a beginner and i have recently watched the" Delta Time " tutorial in the learning site and there is something i didn't understand very well so i am going to say what i understood and what i didn't understand :
    " so this function of the Time class is( the time in seconds it took to complete the last frame) and it is used to smooth incremental and decremental operations that affects some value in the Update function so it isn't per frame rather per Seconds . so here is what i do not understand : how can multiplying the variable
    that we are changing its value by DeltaTime does what i said early!!!
    "please correct me if i understood something wrong"
     
  2. renaissanceCoder1

    renaissanceCoder1

    Joined:
    Apr 8, 2015
    Posts:
    127
    Realize that timeDelta will be different each frame - since each frame takes a different amount of time to update. So by multiplying values by timeDelta (in the Update() event function), you are actually just making sure that the value is dependent upon time - rather than frames (since framerate is unpredictable).

    So think about it like this - lets say there is a bit of lag and time between update cycles is rather large. This would then mean that the values you multiply timeDelta by will be larger - which makes sense because more time has passed so you should make larger changes, depending on what you are doing.

    This is why when you multiply values by timeDelta it appears as if things move slower - because timeDelta is often a small value.
     
  3. fares90

    fares90

    Joined:
    May 9, 2015
    Posts:
    3
    thanks i appreciate your help :)
     
  4. Rick Love

    Rick Love

    Joined:
    Oct 23, 2014
    Posts:
    76
    Time.deltaTime is the same as 1/Framerate (FPS).

    FPS (Framerate) is Frames Per Second
    Time.deltaTime is Seconds Per Frame

    When you multiply by deltaTime, it is the same as dividing the effect by the current frame-rate. So if you add up the effects over a single second, they would add up to applying the same effect one time in that second.


    In other words:

    If you want something to happen during a second, you can use deltaTime to apply that effect over the time that has passed in a single frame. Then, your effect will happen during each frame according to how long that frame took. Even if the frame-rate changes, the result will end up adding to approximate the desired outcome.


    Formula:

    Goal: Move 10 meters per second (m/s)

    Assume Time.deltaTime = 0.02 seconds per frame (s/f) = 50 Frames Per Second

    10m/s * 0.02 s/f = 0.2 m/f

    10 meters per second
    * 0.02 seconds per frame
    = 0.2 meters per frame


    As Time.deltaTime changes according to the framerate, the amount of meters to move for that frame will change also.
     
    Last edited: Jul 7, 2015
  5. fares90

    fares90

    Joined:
    May 9, 2015
    Posts:
    3
    thanks, know i have a clear understanding.