1
votes

I fine tuned my 2d platformer physics and when I added slow-motion I realized that it is messed up.

The problem I have is that for some reason the physics still depends on framerate. So when I scale down time elapsed, every force is scaled down as well. So the jump force is scaled down, meaning in slow-motion, character jumps vertically smaller height and gravity force is scaled down as well so the character goes further in the air without falling.

I'm sending update function in hopes that someone can help me out here (I separated vertical (jump, gravity) and walking (arbitrary walking direction on a platform - platforms can be of any angle) vectors):

characterUpdate:(float)dt
{
    //Compute walking velocity
    walkingAcceleration     = direction of platform * walking acceleration constant * dt;
    initialWalkingVelocity  = walkingVelocity;

    if( isWalking )
    {
        if( !isJumping )
            walkingVelocity = walkingVelocity + walkingAcceleration;

        else 
            walkingVelocity = walkingVelocity + Vector( walking acceleration constant * dt, 0 );
    }

    // Compute jump/fall velocity
    if( !isOnPlatform )
    {
        initialVerticalVelocity = verticalVelocity;
        verticalVelocity        = verticalVelocity + verticalAcceleration * dt;
    }

    // Add walking velocity
    position = position + ( walkingVelocity + initialWalkingVelocity ) * 0.5 * dt;

    //Add jump/fall velocity if not on a platform
    if( !isOnPlatform )
        position = position + ( verticalVelocity + initialVerticalVelocity ) * 0.5 * dt;

    verticalAcceleration.y = Gravity * dt;
}
1
Can you explain what "dt" is?Bob Montgomery
fixed it by removing the time scale (dt) from all accelerations.DD.
I kinda figured that the "dt," since it was multiplied through in every equation, was the issue.Bob Montgomery

1 Answers

1
votes

You should Fix your Timestep,, if you are multiplying the dt everywhere, everything will depend on that value, making you lose control.