Nvidia PHYSX ragdolls
Project Details
2 weeks, half time
Solo Specialization project at The Game Assembly
Created with our custom engine based on The Game Assembly's in-house engine TGE & the Nvidia PhysX API
C++
3rd Party Libraries: PhysX 4.1, DirectX 11, FMOD, Nlohmann Json, ImGui
RAGDOLLS powered by physx Articulations
In this showcase, I'll be discussing some of the key concepts and techniques involved in using PhysX Articulations to create Ragdolls, as well as sharing an example of how I've implemented this technology in an engine.
Ragdolls are a type of physics-based character animation that simulate the movement and behavior of a character's limbs and body. With the power of PhysX, we can create ragdolls that react to collisions, falls, and other environmental factors in a way that looks and feels incredibly realistic.
Characters falling to their death after a shockwave
Characters obliterated from an explosion
Above, you can see the PhysX Visual Debugger (PVD) in action, a networked tool developed by Nvidia to visualize its physics simulation. Simply setting up a connection during the foundation creation process for Nvidia will connect your simulation to the PVD as it is networked.
Very useful for debugging and the early stages of a PhysX setup to visualize.
Articulation
An articulation is a single actor comprising a set of links (each of which behaves like a rigid body) connected together with special joints. Every articulation has a tree-like structure - so there can be no loops or breaks. Their primary use is modelling physically actuated characters. They support higher mass ratios, more accurate drive models, have better dynamic stability and a more robust recovery from joint separation than standard PhysX joints. However, they are considerably more expensive to simulate.
Above you can see the links highlighted in yellow.
PhysX Joints
Each time a link is created beyond the first, a PxArticulationJoint is created between it and its parent.
Below I'm creating up the root link for the articulation, the root link has no joint which is important.
Articulations Links
Below is a recursive function for creations of articulationlinks for a rigidbody, some of the limbs have its links reduced in size to accurately represent this specific character.
I'd like to be more detailed in the shapes, but due to time constraints i took a decision to create it with automation; which could be useful if you were to hand this over to another programmer who seeks to implement ragdolls quickly & easy.
Animating the characters skeleton from the simulation data
In this code snippet you see a tranformation of the articulationlink to be assigned to the animated characters skeletons joints.
First off i had to diconnect the animation state machine, i did so with a single bool to do this and i also saved the pointer to the model to save some performance. I found it acceptable for this showcase.
The engine I'm using for this showcase uses cm whilst PhysX as a standard convention of m. Another aspect that i had to consider doing this showcase is that PhysX only uses GlobalPos(World Space) & ActorSpace(LocalSpace); so translating to an engine that also uses model space was in itself not so easy to figure out.
Updating the skeleton using the mapped links transforms
myPhysxLinkMap.myDeathPose->JointTransforms[i] = rotationMatrix * translationMatrix * myGameObject->GetTransform().GetMatrix().GetInverse();
The expression on the right side of the assignment operator calculates the transformation matrix for the current joint using the current orientation and position of the joint in the PhysX simulation. The transformation is then combined with the inverse of the transformation of the GameObject associated with the PhysX simulation (our characters 4x4Matrix). Effectivly taking it to world space. This is achieved by multiplying the rotationMatrix and translationMatrix with the inverse of myGameObject's transform matrix. The resulting matrix represents the final transformation for the joint in world space, which can be used to render the character's animation.