Delta Time speed problem

Discussion in 'Programming' started by SQGTDev, Dec 30, 2018.

  1. SQGTDev

    SQGTDev Member

    Joined:
    Nov 11, 2016
    Posts:
    65
    I'm having a very bizarre delta time problem that I can't figure out how to fix.

    Accelerations actually work perfectly, since I followed this tutorial: https://web.archive.org/web/2016030...ksula.hut.fi/~hkankaan/Homepages/gravity.html

    The problem is this: when I make my player object jump, and I apply gravity on the next frame, the jump height changes depending on the framerate. If I apply gravity on the same frame, then it works perfectly across all framerates and the object will reach the exact same height each frame.

    Here's my delta time code that runs before the player object's events:
    Code:
    framerateDelta = (framerateInternal / 1000000) * delta_time;
    Here's my player object's code:
    Code:
    #region //Controls
        var xAcc = 0, yAcc = 0, xAccTemp = 0, yAccTemp = 0;
        var delta = objGameController.framerateDelta;
        var left = objGameController.controlsInput[@ 0, 0];
        var right = objGameController.controlsInput[@ 0, 1];
        var up = objGameController.controlsInput[@ 0, 2];
        var down = objGameController.controlsInput[@ 0, 3];
        var Abutton = objGameController.controlsInput[@ 0, 4];
        var Bbutton = objGameController.controlsInput[@ 0, 5];
        var inputHorizontal = right | (left << 1);
        var inputVertical = down | (up << 1);
    #endregion
    
    switch (state)
    {
        case 0:
            #region //State Normal
                #region //Init
                    var onGround = ground[@ 0];
                #endregion
                #region //Physics
                    switch (ground[@ 0])
                    {
                        case true:
                            break;
                        case false:
                            yAcc += 0.25;
                            break;
                    }
                #endregion
                #region //Actions
                    if left = (buttonHold)
                    {
                        xAcc -= 0.5;
                    }
                    else if right = (buttonHold)
                    {
                        xAcc += 0.5;
                    }
                    if (Abutton = buttonPress)
                    {
                        if (onGround = true)
                        {
                            ySpeed = -7;
                            ground[@ 0] = false;
                        }
                    }
                #endregion
                xAccTemp = xAcc * delta;
                yAccTemp = yAcc * delta;
                xTemp += delta*(xSpeed + (xAccTemp * 0.5));
                yTemp += delta*(ySpeed + (yAccTemp * 0.5));
                xSpeed += xAccTemp;
                ySpeed += yAccTemp;
                xSpeed = clamp(xSpeed, -3, 3);
            #endregion
            break;
    }
    If I move the physics region below the actions (which contains jumping) region, the jump heights work perfectly, but if I keep it above the actions region, the jump heights become inconsistent. I have a feeling it has to do with the initial jump speed not having accelerations applied for one frame.
     
  2. Becon

    Becon Member

    Joined:
    Jul 13, 2016
    Posts:
    109
    I'm actually not sure what you want here. Do you want your forward speed to NOT affect your vertical height? Also...you said how it DOES work. What problems does that cause that you DON'T want to do it that way??
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice