Physics character by default is driven purely by simulation. Although pose tracking can be used to bias the simulation toward desired kinematic motion, it is difficult to keep the character stand upright or fixed some body link exactly. The constraint is introduced to provides this functionality. For example, instead of developing a complicated balance controller to have the character maintain upright pose, we can constrain the character's root to prevent him from falling down. Also, we can constrain a character's hands to a moving objects and have that object drive the character's global movements. This can create effects like a character grabbing a bar or ladder from a helicopter, etc. Note that although some body links are constrained, the other parts are still in effects for physical simulation and pose tracking can still work for the rest of joints.
To setup constraints :
- Select the body link to be constrained :
- bodyLink = phyManager.getJointObj("charName","jointName"); # get corresponding body link from a character
- bodyLink.setBoolAttribute("constraint", true); # enable constraint
- If we do not specified a constrain target ( the target object which the body link will follow ), then the body link will follow its kinematic motion. This is used when user want some body links ( for example, the foot ) to exactly match the desired kinematic trajectory.
- If we want to fix the body link to a target object, we need to specify the name for that object.
- bodyLink = phyManager.getJointObj("charName","jointName"); # get corresponding body link from a character
- bodyLink.setBoolAttribute("constraintTarget",targetPawnName); # set the constraint target to a pawn
Note that although the physical simulation will try to accommodate user specified constraints as much as possible, it can not handle constraints that conflict the character setup. For example, if user sets up constraints that control each hand, the distance between two constraints can not exceed the total length of both arms. Otherwise the character will not be able to perform such a task and simulation would become unstable to satisfy the conflicting goals.