//pseudo code, not sure if gravity vector is always added, or only when falling
simulated function TickMove(float dt) { // dt is deltatime, the maount of time that has passed since the last frame
local vector vMoveDelta;
local vector vClampVel;
// calculate clamped velocity
vClampVel = Velocity + acceleration*dt;
if(Physics == PHYS_Walking) vClampVel = Normal(vClampVel) * FMin(VSize(vClampVel), GroundSpeed);
else if(Physics == PHYS_Falling){
vClampVel.Z=0; // don't take into account the vertical component when clamping velocity while falling
vClampVel = Normal(vClampVel) * FMin(VSize(vClampVel), GroundSpeed) + gravity*dt + Velocity.Z * vect(0,0,1); // don't forget to add gravitational "pull" and the existing Z component of velocity
}
else if(Physics == PHYS_Flying) vClampVel = Normal(vClampVel) * FMin(VSize(vClampVel), AirSpeed);
else if(Physics == PHYS_Swimming) vClampVel = Normal(vClampVel) * FMin(VSize(vClampVel), WaterSpeed);
vMoveDelta = vClampVel*dt;
MoveSmooth(vMoveDelta);
}