Hello! =)
**Short form**: Is there anywhere I can see how much force has been added to a kinematic rigidbody over the course of the current frame?
Alternatively:
Is there a way to catch or hook into [AddForce()][1] **method invocations**, so that whenever *[some script]* calls AddForce() on a particular rigidbody, I can execute some code that does something with the **parameters** of the call?
**Long version:**
Ok, so what I'm attempting to achieve here is to '**ragdoll**' a character when the **force applied** to it **exceeds a threshold.**
The (Non-humanoid) character consists of a regular Unity character controller and a collection of Kinematic rigidbodies, that are used as hitboxes for it's body and limbs.
I ragdoll the character using a script which deactivates the character controller and animator and sets the rigidbodies to non-kinematic. This works well enough, physics takes over and the character falls over as per the joints configured for the rigidbodies.
My problem lies in triggering the ragdoll state. I want the character to ragdoll upon losing it's balance. My approach is to add together the forces being applied to the character into an 'imbalance' vector, and if this vector's magnitude exceeds a threshold, the character is ragdolled and it falls over.
This is fine for collisions with physics controlled rigidbodies; I can simply calculate the force of the impact in OnCollisionEnter and add it to the running total, but I can't find any similar solution to forces caused by non-collisions.
This means that wind effects, explosions, or any force applied by a script don't contribute to triggering the ragdoll.
The only workable solution I can see at the moment is to modify every script I use that applies forces and add a check for the ragdoll'able character and apply the imbalance directly. This isn't ideal, it'd clutter up those scripts and introduce difficult to detect bugs where I forget a particular call, or don't account for the Forcemode by accident.
Where should I go from here? Is the ugly way my only option? Is there a better, smarter design that doesn't have this issue?
[1]: http://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html
↧