Skip to main content
GameDev.net gamedev.net
🔒 Locked

Warm-starting for 3D rigid bodies

Started by fractali Aug 25, 2025 at 2:10 PM 7 replies 2.7k views
Original Post
fractali
fractali

Hi, I was curious on how others typically do warm starting when solving contact constraints. Mainly, what do you use as the IDs for each contact point.

I'm currently using an ID that's combines the rigid bodies IDs, the reference face index, the incident face point index, and the 2 clipping edges used to potentially clip the incident face point. My contact detection biases one of the rigid bodies so the reference and incident faces stay consistent across timesteps.

Now, there a couple of issues I've seen.

  1. If a box was clipped by 2 edges, then rotates slightly so it's only clipped by 1 edge, the contact point ID changes and we lose a frame of warm starting.
  2. When storing the impulses to be used in the next frame, I don't remove contacts that no longer exist, in case they exist in a later frame. I initially only stored the impulses that were used in the current frame and remove the caches that no longer exist, but that was less stable than not removing the non-existant contact because as a stack of boxes jitter, that contact may be found again and the previously unused cache will now be used. I've seen other physics engines just remove impulses that don't exist in the current frame, and I'm not a big fan of keeping them in cache due to not knowing when should I remove them. Anyone else experience this?

Context: Using a PGS solver. SAT for contact detection.

Aressera
Aressera

I don't compute any IDs for contacts and instead use the previous contact point in the local space of each object to identify matches. If the euclidean distance between the old and new points is less than a threshold then I consider them to be the same. This fixes your issue from (1). The concept of a contact ID doesn't make very much sense with quadric shapes (spheres, capsules, cylinders).

For #2, I can see how keeping invalid contacts around can help with stacking stability, but be aware that that might cause you to get wrong results in other circumstances. Your physics simulation will no longer be as accurate if objects are not statically stacked. I wouldn't keep invalid points around for more than 1 or 2 extra frames. I think I tried this once to deal with jitter but ultimately removed it.

fractali
fractali

Thanks Aressera, that makes sense. For the distance check, do you check that both of the contact objects local space distance is more than your threshold then you don't apply the impulse, or just if a single objects local space distance has change. I'm thinking of the scenario where we have a cube sliding down a ramp, the cube's local coordinates for the contact are the same frame-to-frame, but the ramps changes as the cube slides down. If the cube slides fast enough it then the distance check from the ramps local space would fail.

Aressera
Aressera

You are correct, a match is found if either distance in local space is less than the threshold, to handle the exact case you describe.

fractali
fractali

Thanks so much Aressera!

fantasyAlgo
fantasyAlgo

Hi, I'm sorry for entering this conversation, but I don't want to open another thread.

I'm trying to compute the contact points using the method Aressera kindly described, but in my tests GJK-SAT/EPA always finds the same point in local space (+ or - some threshold). How do you force it to compute a different contact point (in 3d)?


Thank you in advance.

Dirk Gregorius
Dirk Gregorius

This might be helpful. I go over a lot of different shapes and different approaches

https://media.steampowered.com/apps/valve/2015/DirkGregorius_Contacts.pdf

Aressera
Aressera

fantasyAlgo said:
I'm trying to compute the contact points using the method Aressera kindly described, but in my tests GJK-SAT/EPA always finds the same point in local space (+ or - some threshold). How do you force it to compute a different contact point (in 3d)?

That's expected until the objects move as a result of the first collision point. GJK/EPA only find the point with greatest penetration. You start with just 1 contact point, then that point causes a torque on the object(s) which causes a different point to be found on later frames. Use a cache of contacts (maximum 4 typically) to make a stable manifold. If you want to do better you can do a more complicated calculation like Dirk describes to get a full contact manifold on the first frame of the collision.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.