# Physics based characters?

In gta 5, if you walk off a cliff your body tumbles down even while your alive, and the movements are driven by physics and animation, how would this be achieved in unity?

Also more features such as getting shot being able to knock you over, large objects knocking you over, etc.

I want to use advanced physics driven movement in my 3ps Fps game.

Fun experiment: place the first person controller down, then rotate it forward. Try to move around.

i think tumbling effects and such are done with ragdolls.

As to doing physics properly in general, a good start is to have your character move around and jump using Applyforce, as well as giving them a rigidbody and a sensible mass for their size.

would be interesting to see others’ input on this. that’s about as far as i’ve gotten for now

What about the animators; “apply physics” could that be used for animating the player using physics?

With Unity, ConfigurableJoints can have a target orientation and apply forces to reach that position.

For pose matching, you’d basically have a hidden version of your character, powered by normal animation, and a physical version of your character where each joint is trying to match the orientation of the animated version.

We did this in Minotaur China Shop, although the game was deliberately meant to be clumsy. You’re going to have a seriously difficult time accomplishing precise/FPS movement here.

Here’s a 6-year old video (!):

https://vimeo.com/2474951

And the actual code on each joint (UnityScript):

``````#pragma strict
@script RequireComponent(ConfigurableJoint)

// the object we're trying to match
var target:Transform;

// our individual strength
var strength:float = 1.0;

// our starting angle
private var initialRotation:Quaternion;

// our initial strengths
private var initialSpring:float;
private var initialDamper:float;

// cache
private var transformC:Transform;
private var jointC:ConfigurableJoint;

/**
* Set up our initial values
*/
function Awake()
{
transformC = transform;
initialRotation = transformC.localRotation;

jointC = GetComponent(ConfigurableJoint);

initialSpring = jointC.slerpDrive.positionSpring;
initialDamper = jointC.slerpDrive.positionDamper;
}

/**
* Change the joint angle target to match our target's
*/
function FixedUpdate()
{
if(!target)
return;

jointC.targetRotation = Quaternion.Inverse(target.localRotation) * initialRotation;
}

/**
* Modify our joint strength by a percentage
*/
function SetStrength(newStrength:float)
{
// modify by our individual strength
newStrength *= strength;

// negatives will probably freak out the physics engine
if(newStrength < 0.0)
newStrength = 0.0;

var positionDamper = initialDamper * newStrength;
var positionSpring = initialSpring * newStrength;

jointC.slerpDrive.positionDamper = positionDamper;
jointC.slerpDrive.positionSpring = positionSpring;

jointC.angularXDrive.positionDamper = positionDamper;
jointC.angularXDrive.positionSpring = positionSpring;

jointC.angularYZDrive.positionDamper = positionDamper;
jointC.angularYZDrive.positionSpring = positionSpring;
}
``````

Joint angles are defined relative to the starting position of the joint, not in the object’s local frame relative to its parent. You’ll need to do a little Quaternion/rotation math there to compensate, but really, that’s the meat of it.

Oh, and if you’re looking at doing something based on ragdoll bipeds Adam Mechtley’s “Biped” package in the UAS is seriously worth your money: Unity Asset Store - The Best Assets for Game Making

Minotaur China Shop! lol