Linear Damping towards one axis?

So I wanted a physics related object to move faster in the Y Axis, but slower on the Z Axis. Right now I’m moving it by radial impulses. It is basically pulled to where I click on with the mouse, but I really need different speeds depending on the axis, I can’t think of simple answers to this, it would be pretty easy if I could break the linear damping into vectors, but since that’s not possible, I need some light.

did you get any answer to that yet? I’m curious about that and I’ve been googling for ways to do it without success so far, my main issue is that the dampling is applied to gravity which I would rather leave intact

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

The main issue is that I want dampling on most of what happens to an actor but still keep gravity intact, what do you think would be the best way of doing that?

It kind of bars solution 1 and 2 unless you think I should start manually applying gravity or something

Then I would leave damping the same, and just apply less force to an object depending on the axis.

Can’t do chief, I need damping because I need my actor to slow down over time (but never slow down while falling)

If physics simulating you can GetLinearVelocity and multiply that by a number between 0 amd 1 like 0.1 every tick, but only for two of the axes, and just feed the original back in when you call a SetLinearVelocity in the same function.

If not physics simulating you can do likewise but use Get Velocity and Set Velocity instead.

Not sure how clean or realistic or problematic this approach is but try it and and let me know.

Oh yeah and mult by deltatime too because you dont want framerate messing it up.

Then Go with my Solution #3.
If you want this to be a multi-purposed solution for many objects, write it into a component that you can attach to physics actors you want to have this behavior.

  • Set 0 for the default LinearDamping float variable on the physics object, or it will get dampened twice :smiley:
  • Set the new LinearDamping vector to something like Vector3(0.5, 0.5, 0.1) or 0 in Z if you want no air resistance.
  • Have the component get all child components from its parent, and select only physics components. Store those in an array.
  • On tick run the solution 3 code for each physics body that is simulating physics.