private void UpdateVelocity(PhysicsObject currentObject) { // To avoid errors (specifically, NaN), remove velocity if too small. if (Player.Velocity.Length <= Constants.Physics.MinSpeed) { Player.Velocity = Vector3d.Zero; } // Gravity currentObject.Accelerate(-Vector3d.UnitY * Constants.Physics.Gravity); // Buoyancy currentObject.Accelerate(Vector3d.UnitY * currentObject.BuoyancyMagnitude); // Surface friction Vector3d horizontalVelocity = Vector3d.Multiply(currentObject.Velocity, new Vector3d(1, 0, 1)); if (IsOnGround(currentObject) && horizontalVelocity != Vector3d.Zero) { currentObject.Accelerate((-Vector3d.Normalize(horizontalVelocity) * currentObject.KineticFrictionCoefficient * Constants.Physics.Gravity) * horizontalVelocity.Length * Constants.Physics.FrictionSignificance / Constants.Physics.GripSignificance); } // Update velocity currentObject.ApplyAcceleration(); }