• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Delta Time speed problem

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.
 
B

Becon

Guest
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??
 
Top