I threw together an example, I assume this is what you’re referring to:
//start of each frame, save previous velocity
Vector3 previousVelocity = velocity;
// by the way, I would recommend using this for more consistent frame pacing
float deltaTime = (float)gameTime.ElapsedGameTime.Ticks / TimeSpan.TicksPerSecond;
// unit consistent in my game world for scale
// I multiply this onto my velocities when I initialize
float unitOfMeasure = 64.0f;
float gravityV = 9f * unitOfMeasure; // gravity velocity
if (IsGrounded) // feet on ground
{
if (InputMap.JustPressed(player, Actions.Jump)) // jump input
{
velocity.Y = jump.verticalRate; // jump.verticalRate = 11f * unitOfMeasure
}
}
// add force of gravity to current vertical velocity
velocity.Y += gravityV * deltaTime;
if (velocity.Y < -MaxFallRate) // check if we're moving faster than MaxFallRate
{
if (previousVelocity.Y >= -MaxFallRate)
{
velocity.Y = -MaxFallRate;
}
else
{
velocity.Y = previousVelocity.Y;
}
}
// This is called Verlet Integration, as opposed to Euler
// It is mathematically more accurate than adding velocity normally to position
position += (previousVelocity + velocity) * 0.5f * deltaTime;