Hello, Rafael,
any news on this?
I’ve tested one more solution - add a fixed position constraint, when velocity is almost zero. Then, I break this constraint, if Force on this constraint is more than static friction force available. Though it’s not that stable.
Hello Geoff,
I’ve made couple of tests in meantime. Apparently the approach with applying impulse to stop = (-M*V / dt) works, if applied at the right time (partially works
).
I’ve enabled Async Physics Tick and added couple callbacks to try. With such a code body is dead stable (sure, sleeping disabled for the test purposes). This function is wired to OnPostIntegrate_Internal of TSimCallbackObject.
void ATestActor::AsyncPostIntegrate(float DeltaTime, float SimTime)
{
Chaos::FRigidBodyHandle_Internal* Handle = GetInternalHandle(Mesh);
FVector Velocity = Handle->V();
FVector ImpulseToStop = -Velocity * Handle->M();
//const float FrictionAvailableThisFrame = FrictionForceValue * DeltaTime;
//FVector FrictionImpulse = ImpulseToStop.GetClampedToMaxSize(FrictionAvailableThisFrame); <-- optionally clamp to friction force available
Handle->SetV(Velocity + ImpulseToStop / Handle->M());
}
Such code counteracts gravity and any internal push forces applied, because it adjusts velocity right after integration of forces happens.
The issue still is collisions. Since collisions are solved as constraints at position level, I think I cannot simply override velocity/impulse there (since velocity is derived from position solution). Thus I tried to do so, it makes no sense, because positions are already updated.
I’m now considering making a “Friction” constraint - a constraint with all axes unlocked, with motor + velocity target = 0, and setting maximum force to be an available friction force this frame (taking into account, friction is a constraint, which tries to stop body movement).
Let me know, if all these make sense.
Best regards,
Bohdan
Hello Geoff,
I’m investigating options, where player can potentially couple any cart type to any cart type (2 opposing locomotive carts? OK. 10 braking carts with 2 loco carts in the middle pushing opposite directions? why not). The problem with using built in friction is that my carts now have no contact manifolds (so no body to friction against). They are “beads on wire” - bodies constrained to local X axis movement in air.
Another thing, I’ve recently seen, is PBDSuspensionConstraints, which creates fake Contact Manifolds to hard stop suspension from touching the ground. This said, to use built-in friction it might be possible to somehow fake the contact manifolds and let solver solve it. For example, it might be possible to create something like that on a diagram:
[Image Removed]It’s possible to call FPBDCollisionSolver::SetFriction and specify the bodies/normals. However, is it “easy” to create fake contact points though (e.g. without another creating another constraint type like Suspension)?
If it’s the case, I will try using this approach and let Chaos solver solve the same natural way, as a regular box on incline is solved.
Also, I think, for non-zero velocities I can AddForce(PushForce-FrictionForce) directly to body. The problems arise only when body is colliding or resting.
p.s. We have discussed spline constraints [couple months [Content removed] and I succeeded with creating SplineConstraint inspired by this article. Not a new type, but I constrained body to world, locked axes excluding X axis and update constraint reference frame (orientation and position) to be the closest point on a spline, every tick. This works quite well. In any case, I’m open to chat (email? Discord?).
Best regards,
Bohdan
Hello Geoff,
I paused investigation on this topic for Chaos, but got some good results by creating custom 1D-solution (for splines, tackle spline as a 1D line, I don’t have small-radius curves, so error is negligible) and custom iterative impulse-based solver (inspired by Box2D/Box2D Lite/Erin Catto’s publications), where I applied friction as an impulse constraint and that’s it.
I’ve also checked some PBD/XPBD related papers which tackle friction in different ways, though I think the easiest “generic” solution would be to create another ConstraintContainer (so, new constraint type), make it the highest priority and make this solver to act as “friction” countering any movement from a position solved earlier (clamped by max force/max impulse).
Best regards,
Bohdan
Hello,
I understand, that requested behavior is kinda special and requires either new solutions for Chaos, or some hacks to be done anyway.
So. I think it’s best to close the ticket. I marked the closest answer as Best.
Hope to see new cool features in Chaos in near future though.
Best regards and thanks for cooperation,
Bohdan