Linear Damping towards one axis?

The code that handles LinearDamping is here
DyBodyCoreIntegrator.h | bodyCoreComputeUnconstrainedVelocity

I’ve re-written it a bit to be easier to read

Vector3 linearVelocity
float linearDamping
float deltaSeconds

float linearDampingTimesDeltaSeconds = linearDamping * deltaSeconds
float linearVelocityMultiplier = Max(0.0f, 1.0f - linearDampingTimesDeltaSeconds)
linearVelocity *= linearVelocityMultiplier

This uses a single float to reduce velocity in all directions. To solve your problem, there’s a few options.

Solution 1: You could apply less force when moving the object around based on the velocity direction.

Solution 2: For moving objects around I recommend using the PhysicsHandle, use this instead of a impulses. After grabbing a component, you can move the target location more or less based on direction.

Solution 3: You can put this code into a component or actor, that runs this logic every tick (probably want it post physics tick). You would get the LinearVelocity from the physics component, run this math. Then set the new LinearVelocity. You would then not set the physics component’s actual linear dampening, and just set it here. The only difference, is that here we use a vector for each axis of velocity damping.

Vector3 linearVelocity
Vector3 linearDamping
float deltaSeconds

Vector3 linearDampingTimesDeltaSeconds = linearDamping * deltaSeconds
Vector3 linearVelocityMultiplier = Vector3(
    Max(0.0f, 1.0f - linearDampingTimesDeltaSeconds.X),
    Max(0.0f, 1.0f - linearDampingTimesDeltaSeconds.Y),
    Max(0.0f, 1.0f - linearDampingTimesDeltaSeconds.Z))
linearVelocity *= linearVelocityMultiplier
1 Like