NVIDIAGameWorks / PhysX

NVIDIA PhysX SDK
Other
3.11k stars 793 forks source link

PhysX #570

Closed ProudArts closed 1 year ago

kstorey-nvidia commented 2 years ago

Are you using rigid body collisions or sweeps/overlaps to generate contacts?

Are you reliant on the PhysX solver applying collision forces on the wheel or are you doing this yourself?

The issue is that, in this case, you would want the contact normal for any contact point to point exactly to the COM of the wheel so that the angular velocity does not project any velocity component onto the normal direction. As the shape is not a perfectly cylindrical shape, it is discretized and you get discrete steps on the surface of the wheel. It will roll reasonably smoothly, but as the angular velocity of the wheel increases, small offsets in the contacts can lead to significant pops due to the linear projection of the angular velocity.

There are solutions available. The first option would be to leverage contact modification - you can just take those contact points, project them onto an analytical cylindrical surface and adjust the normal to point back to the COM of the shape. If you do this, you'll get perfectly smooth contacts.

An alternative is to use PxSceneDesc::solverOffsetSlop. This is a parameter that defines a length limit for the angular projection terms used in collision (offset.cross(normal)). If the magnitude of this vector is below solverOffsetSlop, it is zeroed. In PhysX 4, this is a global setting on the scene. More recently, it's been moved to be a per-body property. It will produce a similar effect to the contact mod option above, but the contact mod option will probably produce slightly better results.

You could also look at using a slightly smaller collision geometry and setting a positive rest offset. This has the effect of simulating a sphere-swept shape. It will round edges and faces so it will reduce the amount of discretization. It won't fully solve your issues by itself, but it will make them less of an issue. The other 2 options should - in theory- solve the problems entirely.

There are other options available in PhysX 5, but they're only available through Omniverse at the moment so it probably doesn't help you much.

I hope one of these options can work for you

Kier

kstorey-nvidia commented 2 years ago

I'm glad that one of my suggestions helped.

The normals I'm discussing are the contact normals that are generated by collision detection. These are chosen based on the collision features that are selected and could correspond to one of the two face normals or an edge/edge cross product direction. You can modify these values using a callback that gets invoked from PhysX just after contact generation. This is also where you can do other interesting things like reject contacts, limit forces, adjust material properties etc.

There's a discussion on implementing this in UE4 here:

https://forums.unrealengine.com/t/how-do-i-get-my-contactmodifycallback-to-work/250909

Unfortunately, there's no way to do this without writing some C++. I'm not sure to what extent UE4/UE5 supports modification - it's been something that's been supported in PhysX for as long as I can remember. It's a really powerful feature that allows you to modify the behaviour of collisions to suit your game.

Hope this helps

Kier

amoravanszky commented 2 years ago

@ProudArts I would like to make the totally unhelpful comment that I love your motorbike videos. Best of luck with this project.

Sorry but you should send UE related questions to Epic, we really have no idea.