NVIDIAGameWorks / PhysX-3.4

NVIDIA PhysX SDK 3.4
https://www.nvidia.com/
2.35k stars 273 forks source link

Local Center of Mass Modification In Contact Modifier Callback #60

Closed WombatZilla closed 5 years ago

WombatZilla commented 6 years ago

Hi,

I have a quick question regarding the contact modifier callback. Is it possible to modify the local position of the center of mass on a body in this callback. I am working on some car physics and would like to have a low center of mass on my vehicles while driving so that they have a better driving response but then temporarily shift up the center of mass during collisions so that the solver doesn't generate torques that "ride" the car up a wall due to the low center of mass.

This feature is available in Havok and I think a number of other physics engines also have something similar?

Cheers,

Richard Hunton EA Firemonkeys

rknoesel commented 6 years ago

You could flip that around and put the center of mass where it works well for contacts/collisions, but do your suspension force calculations with a modified COM, assuming you do ray/shape casts for the wheels.

Ralf Knoesel CTO / Founder Vector Unit Inc

© 2017 Vector Unit Inc. Confidential and Proprietary. This email is meant for the intended recipients only. If you have received this email in error, please delete the email and inform rknoesel@vectorunit.com

On Wed, Dec 20, 2017 at 9:21 PM, WombatZilla notifications@github.com wrote:

Hi,

I have a quick question regarding the contact modifier callback. Is it possible to modify the local position of the center of mass on a body in this callback. I am working on some car physics and would like to have a low center of mass on my vehicles while driving so that they have a better driving response but then temporarily shift up the center of mass during collisions so that the solver doesn't generate torques that "ride" the car up a wall due to the low center of mass.

This feature is available in Havok and I think a number of other physics engines also have something similar?

Cheers,

Richard Hunton EA Firemonkeys

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NVIDIAGameWorks/PhysX-3.4/issues/60, or mute the thread https://github.com/notifications/unsubscribe-auth/AGaJLCSj-utYwcunogyMTCIz7ZPUQvoVks5tCerNgaJpZM4RJXdJ .

WombatZilla commented 6 years ago

In my case this is an interesting suggestion but not really what I'm after.

I would like PhysX to step the physics forward on my cars using all the forces and torques I have applied during my car physics calculations (tire lateral / longitudinal grip, suspension, roll bars, aero, drag, rolling resistance, etc) using the lower center of mass but resolve any collisions / contact points in the solver using an offset COM.

Cheers,

Richard Hunton EA Firemonkeys

kstorey-nvidia commented 6 years ago

You can modify the location of the contacts during contact modification. This would allow you to move the contact more in-line with your car's COM. Could you try using this to see if you can achieve an acceptable result?

PhysX also provides a mechanism to locally adjust the mass/inertia of the colliding bodies. You can't explicitly modify the values in the inertia tensor but you are provided scales that you can use to scale the inverse mass or inverse inertia of the bodies to tweak the way collisions are handled. This may also be a useful feature for you.

Its not currently possible to adjust the location of the COM of the bodies in the contact solver. It probably wouldn't be very difficult to add, either as an extension to contact mod or as a new property of the rigid bodies.

Assuming the COM is low (e.g. some point below the chassis of the vehicle, outside of the collision geometry), if the vehicle left the ground and began tumbling, the motion would look quite unusual because integration will occur around the COM causing the vehicle to appear to orbit a point outside the chassis.

WombatZilla commented 6 years ago

Thanks for the response. I will try moving the contacts during collision to see if this gives me some interesting results. We are currently using mass, inertia, friction and restitution modifiers in the contact modifier callback and these make the collisions a lot less punishing.

Like you say putting the COM outside the collision geometry would look and behave a bit strange. We are currently running our vehicles with lowish COM's but they are still above the bottom of the car's collision shape. My thought was to run with this low COM for normal driving and then move the COM up during collisions and also when "tumbling" in crash mode,

My current nasty collision response case in on highly cambered sweeping corners with vertical walls at the top of the corner. Hitting these walls at a glancing angle at high speed is pretty nasty,

If adjusting the COM in the contact modifier callback was a simple change I'd love to have a patch to try out locally :)

But for the moment I'll try moving the contact points and also will have a close look at what our suspension simulation code (springs, dampers, roll bars, bump stops) is doing during high speed collisions.

Cheers,

Richard Hunton EA Firemonkeys