NVIDIAGameWorks / PhysX

NVIDIA PhysX SDK
Other
3.19k stars 808 forks source link

Implement pushing of dynamic actors by Kinematic CCT #488

Open elderkeltir opened 3 years ago

elderkeltir commented 3 years ago

Hello,

I want to implement a good-quality, generic mechanism to let Kinematic CCT push some dynamic actors. Which model is better to use: elastic or non-elastic collision? Both have some pros and cons, imo. Another case is when cct's velocity is 0 at the moment of collision with dynamic actor: say we stand right near dynamic actor and want to push it, how to integrate this into above algorithms? Say I want to be able to push heavy cupboard in a realistic way. As well as kicking small chair. I'd like to have some physics based model, but I assume I will need to tweak it to have a "good look".

Any advice is appreciated. If you can point me to some code in PhysX to dig for ideas will be extremely useful.

Thnx!

PierreTerdiman commented 3 years ago

With the "kinematic character controller" pushing dynamic objects around is implemented by users in contact callbacks (called when the character touches objects). It is usually up to users to apply forces or impulses or whatever is appropriate for their game, to push objects around.

Note that as long as you model the character with a single capsule (for example), it will probably not interact with objects in a "realistic way" - a real character is not a rigid body capsule. There can be complex code involved in making these interactions realistic (IK to place a character's hands exactly on the surface of the object it pushes, etc, etc). This is beyond the scope of PhysX's character controller.

Now for simple pushing behavior implemented with the aforementioned forces/impulses, you can have a look at the SDK samples. A few of them use character controllers (north pole, custom gravity, bridges...) and in there you can spawn dynamic actors that will then be pushed around by the character controller's capsule. Is this what you are looking for?

elderkeltir commented 3 years ago

hey there,

Thank you for the answer. I read this in the PhysX documentation, and I'm more than agree, that pushing objects with invisible capsule isn't a good way to implement interactions with physic world in AAA game in 2021, but I can't make game designers to believe me on that :-) What I asked was kind of physics model to calculate amount of force/impulse/acc/vel to apply based on input: two bodies with known mass and velocities got hit. This can be solved in few ways, I wanted to get some ideas to make the most realistic pushing. Maybe I could use PhysX alg that is applied when two dynamic bodies got contact :-) Now I almost implemented alg based on Newton's 2nd law and it looks pretty realistic. We can tune the behavior of the push using damping, friction and mass of the object. Not ideal, but good enough for us for now. Here is code snippet:

            const PxF32 speed = ((cct_mass * cct_acceleration) / actor_mass) * dt;

            ::add_force_at_pos(*actor_dynamic, hit.dir * speed, local_pos, PxForceMode::eVELOCITY_CHANGE);

pos will be calculated based on mass centers, because we can't use hit point as it is not deterministic enough.

Regards!