All Classes Namespaces Functions Variables Enumerations Properties Pages
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
PuppetMaster Class Reference

The master of puppets. Enables character animation to be played physically in muscle space. More...

Inherits MonoBehaviour, MonoBehaviour, MonoBehaviour, MonoBehaviour, MonoBehaviour, MonoBehaviour, MonoBehaviour, and MonoBehaviour.

Collaboration diagram for PuppetMaster:
Collaboration graph
[legend]

Public Types

enum  Mode
 Active mode means all muscles are active and the character is physically simulated. Kinematic mode sets rigidbody.isKinematic to true for all the muscles and simply updates their position/rotation to match the target's. Disabled mode disables the ragdoll. Switching modes is done by simply changing this value, blending in/out will be handled automatically by the PuppetMaster. More...
 
enum  UpdateMode
 Normal means Animator is in Normal or Unscaled Time or Animation has Animate Physics unchecked. AnimatePhysics is Legacy only, when the Animation component has Animate Physics checked. FixedUpdate means Animator is used and in Animate Physics mode. In this case PuppetMaster will take control of updating the Animator in FixedUpdate. More...
 

Public Member Functions

void AddMuscle (ConfigurableJoint joint, Transform target, Rigidbody connectTo, Transform targetParent, Muscle.Props muscleProps=null)
 NB! Make sure to call this from FixedUpdate! Creates a new muscle for the specified "joint" and targets it to the "target". The joint will be connected to the specified "connectTo" Muscle. Note that the joint will be binded to it's current position and rotation relative to the "connectTo", so make sure the added object is positioned correctly when calling this. This method allocates memory, avoid using it each frame. More...
 
void RemoveMuscleRecursive (ConfigurableJoint joint, bool attachTarget)
 Removes the muscle with the specified joint and all muscles connected to it from PuppetMaster management. This will not destroy the body part/prop, but just release it from following the target. If you call RemoveMuscleRecursive on an upper arm muscle, the entire arm will be disconnected from the rest of the body. If attachTarget is true, the target Transform of the first muscle will be parented to the disconnected limb. This method allocates some memory, avoid using it each frame. More...
 
void ReplaceMuscle (ConfigurableJoint oldJoint, ConfigurableJoint newJoint)
 NB! Make sure to call this from FixedUpdate! Replaces a muscle with a new one. This can be used to replace props, but in most cases it would be faster and more efficient to do it by maintaining the muscle (the Joint and the Rigidbody) and just replacing the colliders and the graphical model. This method allocates memory, avoid using it each frame. More...
 
void SetMuscles (Muscle[] newMuscles)
 NB! Make sure to call this from FixedUpdate! Completely replaces the muscle structure. Make sure the new muscle objects are positioned and rotated correctly relative to their targets. This method allocates memory, avoid using it each frame. More...
 
void DisableMuscleRecursive (ConfigurableJoint joint)
 Disables the muscle with the specified joint and all muscles connected to it. This is a faster and more efficient alternative to RemoveMuscleRecursive, as it will not require reinitiating the muscles. More...
 
void EnableMuscleRecursive (ConfigurableJoint joint)
 Re-enables a previously disabled muscle and the muscles connected to it. More...
 
void FlattenHierarchy ()
 Flattens the ragdoll hierarchy so that all muscles are parented to the PuppetMaster. More...
 
void TreeHierarchy ()
 Builds a hierarchy tree from the muscles. More...
 
void FixMusclePositions ()
 Moves all muscles to the positions of their targets. More...
 
void SetMuscleWeights (Muscle.Group group, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for all muscles in the specified group. More...
 
void SetMuscleWeights (Transform target, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle that has the humanBodyBone target (works only with a Humanoid avatar). More...
 
void SetMuscleWeights (HumanBodyBones humanBodyBone, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle that has the humanBodyBone target (works only with a Humanoid avatar). More...
 
void SetMuscleWeightsRecursive (Transform target, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle with the specified target and all it's child muscles (when called on the upper arm, will set weights for the upper arm, forearm and hand of the same limb). More...
 
void SetMuscleWeightsRecursive (int muscleIndex, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle of the specified muscle index and all it's child muscles (when called on the upper arm, will set weights for the upper arm, forearm and hand of the same limb). More...
 
void SetMuscleWeightsRecursive (HumanBodyBones humanBodyBone, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle that has the humanBodyBone target (works only with a Humanoid avatar) and all it's child muscles (when called on the upper arm, will set weights for the upper arm, forearm and hand of the same limb). More...
 
void SetMuscleWeights (int muscleIndex, float muscleWeight, float pinWeight, float mappingWeight, float muscleDamper)
 Sets the muscle weights for the muscle with the specified index. More...
 
Muscle GetMuscle (Transform target)
 Returns the muscle that has the specified target. More...
 
Muscle GetMuscle (Rigidbody rigidbody)
 Returns the muscle of the specified Rigidbody. More...
 
Muscle GetMuscle (ConfigurableJoint joint)
 Returns the muscle of the specified Joint. More...
 
bool ContainsJoint (ConfigurableJoint joint)
 Does the PuppetMaster have a muscle for the specified joint. More...
 
int GetMuscleIndex (HumanBodyBones humanBodyBone)
 Returns the index of the muscle that has the humanBodyBone target (works only with a Humanoid avatar). More...
 
int GetMuscleIndex (Transform target)
 Returns the index of the muscle that has the specified target. Returns -1 if not found. More...
 
int GetMuscleIndex (Rigidbody rigidbody)
 Returns the index of the muscle that has the specified Rigidbody. Returns -1 if not found. More...
 
int GetMuscleIndex (ConfigurableJoint joint)
 Returns the index of the muscle that has the specified Joint. Returns -1 if not found. More...
 
void SetUpTo (Transform setUpTo, int characterControllerLayer, int ragdollLayer)
 Sets the ragdoll up as a Puppet. Assigns the specified layers to the animated target and the ragdoll. If setUpTo is the same Transform as the PuppetMaster's, the character will be duplicated and the duplicate will be used as the animated target. More...
 
void Kill (StateSettings stateSettings)
 Kill the puppet with the specified StateSettings More...
 
void Freeze (StateSettings stateSettings)
 Unfreeze the puppet with the specified StateSettings. More...
 
void Resurrect ()
 Resurrect this instance from the Dead or Frozen state (unless frozen permanently). More...
 
void SampleTargetMappedState ()
 The pose that the target will be fixed to if calling FixTargetToSampledState(). This should normally be used only by the Puppet Behaviours. More...
 
void FixTargetToSampledState (float weight)
 Blend the target to the pose that was sampled by the last SampleTargetMappedState call. This should normally be used only by the Puppet Behaviours. More...
 
void StoreTargetMappedState ()
 Stores the current pose of the target for sampling. This should normally be used only by the Puppet Behaviours. More...
 
bool IsValid (bool log)
 Determines whether this PuppetMaster instance is valid for initiation. More...
 

Static Public Member Functions

static PuppetMaster SetUp (Transform target, Transform ragdoll, int characterControllerLayer, int ragdollLayer)
 Sets up a Puppet from the specified ragdoll and target characters. More...
 
static PuppetMaster SetUp (Transform target, int characterControllerLayer, int ragdollLayer)
 Sets up a Puppet using a single ragdoll character. This will duplicate the ragdoll character, remove the ragdoll components from the original and use it as the animated target. More...
 
static void RemoveRagdollComponents (Transform target, int characterControllerLayer)
 Removes all the ragdoll components (except Cloth colliders), including compound colliders that are not used by Cloth. Components on the 'target' GameObject will not be touched for they are probably not ragdoll components, but required by a character controller. More...
 

Public Attributes

State state
 Sets/sets the state of the puppet (Alive, Dead or Frozen) Frozen means the ragdoll will be deactivated once it comes to stop in dead state.. More...
 
StateSettings stateSettings = StateSettings.Default
 Settings for killing and freezing the puppet.. More...
 
Mode mode
 Active mode means all muscles are active and the character is physically simulated. Kinematic mode sets rigidbody.isKinematic to true for all the muscles and simply updates their position/rotation to match the target's. Disabled mode disables the ragdoll. Switching modes is done by simply changing this value, blending in/out will be handled automatically by the PuppetMaster. More...
 
float blendTime = 0.1f
 The time of blending when switching from Active to Kinematic/Disabled or from Kinematic/Disabled to Active. Switching from Kinematic to Disabled or vice versa will be done instantly. More...
 
bool fixTargetTransforms = true
 If true, will fix the target character's Transforms to their default local positions and rotations in each update cycle to avoid drifting from additive reading-writing. Use this only if the target contains unanimated bones. More...
 
int solverIterationCount = 6
 Rigidbody.solverIterationCount for the muscles of this Puppet. More...
 
bool visualizeTargetPose = true
 If true, will draw the target's pose as green lines in the Scene view. This runs in the Editor only. If you wish to profile PuppetMaster, switch this off. More...
 
float mappingWeight = 1f
 The weight of mapping the animated character to the ragdoll pose. More...
 
float pinWeight = 1f
 The weight of pinning the muscles to the position of their animated targets using simple AddForce. More...
 
float muscleWeight = 1f
 The normalized strength of the muscles. More...
 
float muscleSpring = 100f
 The positionSpring of the ConfigurableJoints' Slerp Drive. More...
 
float muscleDamper = 0f
 The positionDamper of the ConfigurableJoints' Slerp Drive. More...
 
float pinPow = 4f
 Adjusts the slope of the pinWeight curve. Has effect only while interpolating pinWeight from 0 to 1 and back. More...
 
float pinDistanceFalloff = 5
 Reduces pinning force the farther away the target is. Bigger value loosens the pinning, resulting in sloppier behaviour. More...
 
bool updateJointAnchors = true
 When the target has animated bones between the muscle bones, the joint anchors need to be updated in every update cycle because the muscles' targets move relative to each other in position space. This gives much more accurate results, but is computationally expensive so consider leaving it off. More...
 
bool supportTranslationAnimation
 Enable this if any of the target's bones has translation animation. More...
 
bool angularLimits
 Should the joints use angular limits? If the PuppetMaster fails to match the target's pose, it might be because the joint limits are too stiff and do not allow for such motion. Uncheck this to see if the limits are clamping the range of your puppet's animation. Since the joints are actuated, most PuppetMaster simulations will not actually require using joint limits at all. More...
 
bool internalCollisions
 Should the muscles collide with each other? Consider leaving this off while the puppet is pinned for performance and better accuracy. Since the joints are actuated, most PuppetMaster simulations will not actually require internal collisions at all. More...
 
bool broadcastCollisions
 If this flag is false, the MuscleCollisionBroadcasters will not broadcast collision events to the Puppet Behaviours. This value should be set by Puppet Behaviours only. More...
 
Muscle[] muscles = new Muscle[0]
 The Muscles managed by this PuppetMaster. More...
 
UpdateDelegate OnPostInitiate
 Called after the puppet has initiated. More...
 
UpdateDelegate OnRead
 Called before (and only if) reading. More...
 
UpdateDelegate OnWrite
 Called after (and only if) writing More...
 
UpdateDelegate OnPostLateUpdate
 Called after each LateUpdate. More...
 
UpdateDelegate OnFixTransforms
 Called when it's the right time to fix target transforms. More...
 
UpdateDelegate OnHierarchyChanged
 Called when the puppet hierarchy has changed by adding/removing muscles More...
 
List< SolverManagersolvers = new List<SolverManager>()
 The list of solvers that will be updated by this PuppetMaster. When you add a Final-IK component in runtime after PuppetMaster has initiated, add it to this list using solver.Add(SolverManager solverManager). More...
 
bool storeTargetMappedState = true
 Store the mapped state of the target automatically? More...
 

Properties

Transform targetRoot [get, set]
 The root Transform of the animated target character. More...
 
Animator targetAnimator [get, set]
 Gets the Animator on the target. More...
 
Animation targetAnimation [get, set]
 Gets the Animation component on the target. More...
 
BehaviourBase[] behaviours [get, set]
 Array of all Puppet Behaviours More...
 
bool isActive [get]
 Returns true if the PuppetMaster is in active mode or blending in/out of it. More...
 
bool initiated [get, set]
 Has this PuppetMaster successfully initiated? More...
 
UpdateMode updateMode [get]
 Gets the current update mode. More...
 
bool controlsAnimator [get]
 If the Animator's update mode is "Animate Phyics", PuppetMaster will take control of updating the Animator (in FixedUpdate). This does not happen with Legacy. More...
 
bool isBlending [get, set]
 Returns true if the PuppetMaster is in the middle of blending from a mode to mode. More...
 
bool isKilling [get, set]
 Is the puppet in the middle of a killing procedure (started by PuppetMaster.Kill())? More...
 
bool isAlive [get]
 Is the puppet alive or still dying? More...
 
bool isFrozen [get]
 Is the puppet frozen? More...
 

Detailed Description

The master of puppets. Enables character animation to be played physically in muscle space.