Humanoid Control for Unity v4
|
Control avatars using tracking and animation options.
The Humanoid Control component has all the options to control your avatar in a simple way. This document describes the available settings.
Targets are used to move the body. The control of an avatar is split into six body parts: head, 2 arms, torso and 2 legs. Each body part is controlled by a target: Head, Left/Right Hand, Hips and Left/Right Foot. Targets are not shown in the hierarchy by default but can be made visible by clicking on the Show button for that target.
Instead of the normal targets, you can also use custom target by replacing the default targets with references to other transforms.A good example are hands which are connected to a steering wheel. In this example two empty GameObjects are set at the right locations of the steering wheel. The Left and Right Hand Target show then point to the Transforms of these empty GameObjects.
Every target will have Target script attached which give additional control over these targets:
Enables you to choose which tracker devices are supported. Any combination of trackers can be chosen, even when the device itself is not present. Only when the devices are actually present in the system they will be used in the tracking. During game play you can see in the inspector which Input devices are actually present and tracking at any point. Humanoid Control will combine multiple trackers using sensor fusion to achieve the best possible tracking result. See the list of supported devices to get information on the settings forf each device.
Procedural and Mecanim animations are supported for body parts not being tracked by an input device. Mecanim animation is used when an appropriate Animation Controller is selected as parameter. Built-in procedural animation will be used when no Animation Controller is selected. See also Animator.
This will set the base pose of the avatar. For more information see Pose.
For networking setups, a remote avatar has to be selected which is used for the representation of the avatar on remote clients. This enables you to optimise the avatar mesh between first and third person views of the same avatar.
This sets a number of parameters for the locomotion of the avatar:
Inherits MonoBehaviour.
Public Types | |
enum | PrimaryTarget { Head , Hips } |
enum | TargetId { Hips , Head , LeftHand , RightHand , LeftFoot , RightFoot , Face } |
enum | StartPosition { AvatarPosition , PlayerPosition } |
Types of startposition for the Pawn. | |
enum | ScalingType { None , SetHeightToAvatar , ScaleTrackingToAvatar , ScaleAvatarToTracking } |
Types of Scaling which can be used to scale the tracking input to the size of the avatar. More... | |
Public Member Functions | |
delegate void | OnChangeAvatar () |
void | ChangeAvatar (GameObject fpAvatarPrefab) |
void | ChangeAvatar (GameObject fpAvatarPrefab, GameObject tpAvatarPrefab) |
virtual void | LocalChangeAvatar (GameObject avatarPrefab) |
virtual void | InitializeAvatar () |
void | InitAvatar () |
Analyses the avatar's properties requires for the movements. | |
void | ScaleAvatarToTracking () |
Animator | GetAvatar (GameObject avatarRoot) |
Retrieve the avatar rig for this humanoid. | |
void | InitTargets () |
Initialize the targets for this humanoid. | |
void | DetermineTargets () |
Checks the humanoid for presence of Targets and adds them if they are not found. | |
void | MatchTargetsToAvatar () |
Changes the target rig transforms to match the avatar rig. | |
void | UpdateMovements () |
Updates the avatar pose based on the targets rig. | |
void | CopyTargetsToRig () |
Copies the pose of the target rig to the avatar. | |
void | CopyRigToTargets () |
Copies the pose of the avatar to the target rig. | |
void | UpdateSensorsFromTargets () |
Updated the sensor transform from the target transforms. | |
HumanoidTarget.TargetedBone | GetBone (Bone boneId) |
Get the Humanoid Bone. | |
HumanoidTarget.TargetedBone | GetBone (Side side, SideBone sideBoneId) |
Get the Humanoid Bone on the incated side of the humanoid. | |
void | ScaleTrackingToAvatar () |
void | AdjustTracking (Vector3 translation) |
Adjust the tracking origin of all trackers. | |
void | AdjustTracking (Vector3 translation, Quaternion rotation) |
Adjust the tracking origin of all trackers. | |
void | RetrieveBones () |
Scans the humanoid to retrieve all bones. | |
void | OnApplicationQuit () |
delegate void | OnNewNeckHeight (float neckHeight) |
virtual void | SetStartPosition () |
void | Calibrate () |
Calibrates the tracking with the player. | |
delegate void | OnHumanoidPose (HumanoidPose pose) |
void | MoveForward (float z) |
maximum forward speed in units(meters)/second | |
void | MoveSideward (float x) |
Moves the humanoid sideward. | |
virtual void | Move (Vector2 velocity) |
Moves the humanoid in 2D space. | |
virtual void | Move (Vector3 velocity) |
Moves the humanoid. | |
void | MoveWorldVector (Vector3 v) |
void | Stop () |
void | Rotate (float angularSpeed) |
Rotate the humanoid. | |
void | Rotation (float yAngle) |
Set the rotation angle along the Y axis. | |
void | Dash (Vector3 targetPosition) |
Quickly moves this humanoid to the given position. | |
void | Teleport (Vector3 targetPosition) |
Teleports this humanoid to the given position. | |
void | TeleportForward (float distance=1) |
Teleports the humanoid in the forward direction. | |
void | MoveTo (Vector3 position, MovementType movementType=MovementType.Teleport) |
Moves the humanoid to the given position. | |
IEnumerator | RotateTo (Quaternion targetRotation) |
Rotation animation to reach the given rotation. | |
IEnumerator | LookAt (Vector3 targetPosition) |
Rotation animation to look at the given position. | |
IEnumerator | WalkTo (Vector3 targetPosition) |
Movement animation to reach the given position. | |
IEnumerator | WalkTo (Vector3 targetPosition, Quaternion targetRotation) |
Movement animation to reach the given position and rotation. | |
void | Jump (float takeoffVelocity) |
Lets the Humanoid jump up with the given take off velocity. | |
Vector3 | CheckMovement () |
virtual bool | IsMyRigidbody (Rigidbody rigidbody) |
float | GetDistanceToGroundAt (Vector3 position, float maxDistance) |
float | GetDistanceToGroundAt (Vector3 position, float maxDistance, out Transform ground, out Vector3 normal) |
void | SetAnimationParameterBool (string parameterName, bool boolValue) |
void | SetAnimationParameterFloat (string parameterName, float floatValue) |
void | SetAnimationParameterInt (string parameterName, int intValue) |
void | SetAnimationParameterTrigger (string parameterName) |
Vector3 | GetHumanoidPosition () |
The humanoid can be on a differentlocation than the humanoid.transform because the tracking can move the humanoid around independently This function takes this into account. | |
delegate void | OnNewHumanoid (HumanoidControl humanoid) |
bool | IsVisible (Camera camera) |
Is this humanoid visible in the given camera? | |
Static Public Member Functions | |
static void | SetControllerID (HumanoidControl humanoid, int controllerID) |
static void | CheckTargetRig (HumanoidControl humanoid) |
Match the target rig transform to the humanoid transform. | |
static GameObject | GetRealWorld (Transform transform) |
Gets the Real World GameObject for this Humanoid. | |
static GameObject | FindTrackerObject (GameObject realWorld, string trackerName) |
Tries to find a tracker GameObject by name. | |
static HumanoidControl[] | AllVisibleHumanoids (Camera camera) |
Returns all humanoid which are in the frustum of the camera. | |
Public Attributes | |
string | path |
The path at which the HumanoidControl script is found. | |
HeadTarget | headTarget |
HandTarget | leftHandTarget |
The target script to control the left arm bones. | |
HandTarget | rightHandTarget |
The target script to control the right arm bones. | |
HipsTarget | hipsTarget |
The target script to control the torso bones. | |
FootTarget | leftFootTarget |
The target script to control the left leg bones. | |
FootTarget | rightFootTarget |
The target script to control the right leg bones. | |
PrimaryTarget | primaryTarget |
Animator | targetsRig |
The target bones rig. | |
bool | showTargetRig = false |
Draws the target rig in the scene view. | |
Animator | avatarRig |
The avatar Rig. | |
bool | showAvatarRig = true |
Draws the avatar rig in the scene view. | |
float | avatarNeckHeight |
The neck height of the avatar. | |
bool | showMuscleTension = false |
Draws the tension at the joints of the avatar. | |
bool | calculateBodyPose = true |
Calculate the avatar pose. | |
bool | animatorEnabled = true |
Enables the animator for this humanoid. | |
RuntimeAnimatorController | animatorController = null |
The Animator for this humanoid. | |
Pose | pose |
The pose of this humanoid. | |
bool | editPose |
Is true when the pose is currently being edited. | |
IHumanoidNetworking | humanoidNetworking |
The networking interface. | |
GameObject | remoteAvatar |
The remote avatar prefab for this humanoid. | |
int | playerType |
Is true when this is a remote avatar. | |
bool | syncRootTransform = true |
string | remoteTrackerIpAddress |
int | humanoidId = -1 |
The local Id of this humanoid. | |
Cerebellum.Cerebellum | cerebellum |
bool | showRealObjects = true |
If true, real world objects like controllers and cameras are shown in the scene. | |
bool | physics = true |
Enables controller physics and collisions during walking. | |
bool | useGravity = true |
If there is not static object below the feet of the avatar the avatar will fall down until it reaches solid ground. | |
bool | generateColliders = true |
If true, it wil generate colliders for the avatar where necessary. | |
bool | haptics = false |
Will use haptic feedback on supported devices when the hands are colliding or touching objects. | |
StartPosition | startPosition = StartPosition.AvatarPosition |
The start position of the humanoid. | |
bool | calibrateAtStart = false |
Perform a calibration when the scene starts. | |
bool | dontDestroyOnLoad = false |
This option will make sure that the humanoid is not destroyed when the scene is changed. | |
bool | disconnectInstances = false |
(Prefab only) Will disconnect the instance from the prefab when they are included in the scene. | |
bool | gameControllerEnabled = true |
Use game controller input. | |
Passer.Controller | controller |
The game controller for this pawn. | |
int | gameControllerIndex |
The index of the game controller. | |
GameControllers | gameController |
UnityXRTracker | unityXR = new UnityXRTracker() |
The Unity XR tracker. | |
WindowsMRTracker | mixedReality = new WindowsMRTracker() |
The Windows Mixed Reality tracker. | |
WaveVRTracker | waveVR = new WaveVRTracker() |
The Wave VR tracker. | |
NeuronTracker | neuronTracker = new NeuronTracker() |
The Perception Neuron tracker. | |
LeapTracker | leap = new LeapTracker() |
The Leap Motion tracker. | |
RealsenseTracker | realsense = new RealsenseTracker() |
The Intel RealSense tracker. | |
HydraTracker | hydra = new HydraTracker() |
The Razer Hydra tracker. | |
Kinect1Tracker | kinect1 = new Kinect1Tracker() |
The Microsoft Kinect 360/Kinect for Windows tracker. | |
Kinect2Tracker | kinect2 = new Kinect2Tracker() |
The Microsoft Kinect 2 tracker. | |
Kinect4Tracker | kinect4 = new Kinect4Tracker() |
Azure Kinect tracker. | |
AstraTracker | astra = new AstraTracker() |
The Orbbec Astra tracker. | |
OptiTracker | optitrack = new OptiTracker() |
The OptiTrack tracker. | |
TobiiTracker | tobiiTracker = new TobiiTracker() |
The Tobii tracker. | |
ArKit | arkit = new ArKit() |
Tracking.Pupil.Tracker | pupil = new Tracking.Pupil.Tracker() |
The Pupil Labs tracker. | |
DlibTracker | dlib = new DlibTracker() |
The Dlib tracker. | |
AntilatencyTracker | antilatency = new AntilatencyTracker() |
Hi5Tracker | hi5 = new Hi5Tracker() |
CustomTracker | custom = new CustomTracker() |
float | forwardSpeed = 1 |
maximum forward speed in units(meters)/second | |
float | backwardSpeed = 0.6F |
maximum backward speed in units(meters)/second | |
float | sidewardSpeed = 1 |
maximum sideways speed in units(meters)/second | |
float | maxAcceleration = 1 |
maximum acceleration in units(meters)/second/second value 0 = no maximum acceleration | |
float | rotationSpeed = 60 |
maximum rotational speed in degrees/second | |
float | stepOffset = 0.3F |
The maximum height of objects of the ground which do not stop the humanoid. | |
bool | proximitySpeed = false |
Reduces the walking speed of the humanoid when in the neighbourhood of objects to reduce motion sickness. | |
float | proximitySpeedRate = 0.8f |
The amount of influence of the proximity speed. 1=No influence, 0 = Maximum. | |
bool | bodyPull = false |
Will move the pawn position when grabbing handles on static objects. | |
Vector3 | velocity |
The current velocity of the Pawn. | |
Vector3 | targetVelocity |
Vector3 | acceleration |
float | turningVelocity |
bool | triggerEntered |
bool | collided |
Vector3 | hitNormal = Vector3.zero |
Rigidbody | humanoidRigidbody |
Rigidbody | characterRigidbody |
CapsuleCollider | bodyCapsule |
CapsuleCollider | bodyCollider |
Transform | ground |
The ground Transform on which the pawn is standing. | |
Vector3 | groundVelocity |
The velocity of the ground on which the pawn is standing. | |
float | groundAngularVelocity |
The angular velocity of the ground on which the pawn is standing. | |
bool | useLegLengthCorrection = false |
bool | floatCorrection = false |
Correct floating avatars when user is taller than the avatar. | |
bool | floatReverting = false |
bool | isRemote = false |
Is true when this is a remote pawn. | |
ulong | nwId |
The Id of this pawn across the network. | |
int | id = -1 |
The local Id of this humanoid. | |
Protected Member Functions | |
void | Awake () |
float | GetAvatarNeckHeight () |
void | NewTargetComponents () |
void | StartTargets () |
Start the targets for this humanoid. | |
void | UpdateTargetsAndMovements () |
void | UpdateTargets () |
void | InitTrackers () |
void | StartTrackers () |
void | UpdateTrackers () |
void | InitializeTrackingConfidence () |
void | StartSensors () |
void | StopSensors () |
void | SetTrackingHeightToAvatar () |
Adjust Y position to match the tracking with the avatar. | |
virtual void | Update () |
virtual void | FixedUpdate () |
virtual void | LateUpdate () |
virtual void | UpdatePose () |
virtual void | UpdatePoseEvent () |
void | CalculateMovement () |
void | AddCharacterColliders () |
void | DetermineCollision () |
void | CheckGround () |
void | CheckGrounded () |
void | CheckGroundMovement () |
virtual void | CheckBodyPull () |
void | KinematicBodyControlOneHanded (HandTarget handTarget) |
void | KinematicBodyControlTwoHanded () |
virtual void | CalculateVelocityAcceleration () |
void | Fall () |
Protected Attributes | |
ScalingType | scaling = ScalingType.SetHeightToAvatar |
Scale Tracking to Avatar scales the tracking input to match the size of the avatar. | |
Transform | _realWorld |
TraditionalDevice | traditionalInput |
Vector3 | lastHumanoidPos |
float | lastNeckHeight |
Vector3 | lastHeadPosition |
Quaternion | lastHeadRotation |
float | lastHeadDirection |
Vector3 | gravitationalVelocity |
Vector3 | inputMovement = Vector3.zero |
Transform | lastGround |
Vector3 | lastGroundPosition = Vector3.zero |
float | lastGroundAngle = 0 |
float | lastTime |
Properties | |
float | trackingNeckHeight [get] |
The neck height of the target rig. | |
bool | showSkeletons [get, set] |
If enabled, tracking skeletons will be rendered. | |
Transform | realWorld [get] |
The transform containing all real-world objects. | |
HumanoidTracker[] | trackers [get] |
All available trackers for this humanoid. | |
Vector3 | up [get] |
static HumanoidControl[] | allHumanoids [get] |
Returns all humanoids in the current scene. | |
Types of Scaling which can be used to scale the tracking input to the size of the avatar.
SetHeightToAvatar adjusts the vertical tracking to match the avatar size. MoveHeightToAvatar does the same but also resets the tracking origin to the location of the avatar. ScaleTrackingToAvatar scales the tracking space to match the avatar size. ScaleAvatarToTracking resizes the avatar to match the player size.
HumanoidTarget.TargetedBone Passer.Humanoid.HumanoidControl.GetBone | ( | Bone | boneId | ) |
Get the Humanoid Bone.
boneId | The identification of the requested bone |
HumanoidTarget.TargetedBone Passer.Humanoid.HumanoidControl.GetBone | ( | Side | side, |
SideBone | sideBoneId | ||
) |
Get the Humanoid Bone on the incated side of the humanoid.
side | The requested side of the humanoid |
sideBoneId | The identification of the requested bone |
|
protected |
Adjust Y position to match the tracking with the avatar.
This function will adjust the vertical position of the tracking origin such that the tracking matches the avatar. This function should preferably be executed when the player is in a base position: either standing upright or sitting upright, depending on the playing pose. This will prevent the avatar being in the air or in a crouching position when the player is taller or smaller than the avatar itself. It retains 1:1 tracking and the X/Z position of the player are not affected.
void Passer.Humanoid.HumanoidControl.AdjustTracking | ( | Vector3 | translation | ) |
Adjust the tracking origin of all trackers.
translation | The translation to apply to the tracking origin |
void Passer.Humanoid.HumanoidControl.AdjustTracking | ( | Vector3 | translation, |
Quaternion | rotation | ||
) |
Adjust the tracking origin of all trackers.
translation | The translation to apply to the tracking origin |
rotation | The rotation to apply to the tracking origin |
void Passer.Humanoid.HumanoidControl.MoveForward | ( | float | z | ) |
maximum forward speed in units(meters)/second
maximum backward speed in units(meters)/second
maximum sideways speed in units(meters)/second
maximum acceleration in units(meters)/second/second value 0 = no maximum acceleration
maximum rotational speed in degrees/second
Moves the humanoid forward
z | The distance in units(meters) to move forward. |
void Passer.Humanoid.HumanoidControl.MoveSideward | ( | float | x | ) |
Moves the humanoid sideward.
x | The distance in units(meters) to move sideward. |
|
virtual |
Moves the humanoid in 2D space.
velocity | The velocity to move with |
The velocity axis are mapped as follows: x = left/right movement y = forward/backward movement
void Passer.Humanoid.HumanoidControl.Rotate | ( | float | angularSpeed | ) |
Rotate the humanoid.
Rotates the humanoid along the Y axis
angularSpeed | The speed in degrees per second |
void Passer.Humanoid.HumanoidControl.Dash | ( | Vector3 | targetPosition | ) |
Quickly moves this humanoid to the given position.
targetPosition | The position to move to |
void Passer.Humanoid.HumanoidControl.Teleport | ( | Vector3 | targetPosition | ) |
Teleports this humanoid to the given position.
targetPosition | The position to move to |
void Passer.Humanoid.HumanoidControl.TeleportForward | ( | float | distance = 1 | ) |
Teleports the humanoid in the forward direction.
distance | The distance to teleport |
The forward direction is determined by the hips target forward.
void Passer.Humanoid.HumanoidControl.MoveTo | ( | Vector3 | position, |
MovementType | movementType = MovementType::Teleport |
||
) |
Moves the humanoid to the given position.
movementType | The type of movement to use |
IEnumerator Passer.Humanoid.HumanoidControl.RotateTo | ( | Quaternion | targetRotation | ) |
Rotation animation to reach the given rotation.
The speed of the rotation is determined by the #rotationSpeed
targetRotation | The target rotation |
IEnumerator Passer.Humanoid.HumanoidControl.LookAt | ( | Vector3 | targetPosition | ) |
Rotation animation to look at the given position.
The speed of the rotation is determined by the #rotationSpeed
targetPosition | The position to look at |
IEnumerator Passer.Humanoid.HumanoidControl.WalkTo | ( | Vector3 | targetPosition | ) |
Movement animation to reach the given position.
The pawn will walk to the given position. The speed of the movement is determined by #forwardSpeed. Any required rotation will be limited by #rotationSpeed
targetPosition | The position to where the pawn should walk |
IEnumerator Passer.Humanoid.HumanoidControl.WalkTo | ( | Vector3 | targetPosition, |
Quaternion | targetRotation | ||
) |
Movement animation to reach the given position and rotation.
The pawn will walk to the given position and rotation. The speed of the movement is determined by #forwardSpeed. Any required rotation will be limited by #rotationSpeed
targetPosition | The position to where the pawn should walk |
targetRotation | The rotation the pawn should have at the end |
void Passer.Humanoid.HumanoidControl.Jump | ( | float | takeoffVelocity | ) |
Lets the Humanoid jump up with the given take off velocity.
takeoffVelocity | The vertical velocity to start the jump |
|
static |
Gets the Real World GameObject for this Humanoid.
transform | The root transform of the humanoid |
|
static |
Tries to find a tracker GameObject by name.
realWorld | The Real World GameOject in which the tracker should be |
trackerName | The name of the tracker GameObject to find |
Vector3 Passer.Humanoid.HumanoidControl.GetHumanoidPosition | ( | ) |
The humanoid can be on a differentlocation than the humanoid.transform because the tracking can move the humanoid around independently This function takes this into account.
|
static |
Returns all humanoid which are in the frustum of the camera.
camera | The camera in which the humanoids should be visible |
bool Passer.Humanoid.HumanoidControl.IsVisible | ( | Camera | camera | ) |
Is this humanoid visible in the given camera?
camera | The camera in which the humaonid may be visible |
Animator Passer.Humanoid.HumanoidControl.targetsRig |
The target bones rig.
The target bones rig contain the target pose of the avatar The humanoid movements will try to move the avatar such that the target pose is reached as closely as possible
Animator Passer.Humanoid.HumanoidControl.avatarRig |
The avatar Rig.
This is the rig of the avatar we want to control.
bool Passer.Humanoid.HumanoidControl.calculateBodyPose = true |
Calculate the avatar pose.
When this option is enabled, the pose of the avatar is updated from the target rig using the Humanoid movements. If you are only interested in the tracking result, you can disable this option and use the target rig to access the tracked pose.
int Passer.Humanoid.HumanoidControl.playerType |
Is true when this is a remote avatar.
Remote avatars are not controlled locally, but are controlled from another computer. These are copies of the avatar on that other computer and are updated via messages exchanges on a network.
The Id of this humanoid across the network
The Player Type of the humanoid
UnityXRTracker Passer.Humanoid.HumanoidControl.unityXR = new UnityXRTracker() |
The Unity XR tracker.
\
Transform Passer.Humanoid.HumanoidControl.ground |
The ground Transform on which the pawn is standing.
When the pawn is not standing on the ground, the value is null
float Passer.Humanoid.HumanoidControl.groundAngularVelocity |
The angular velocity of the ground on which the pawn is standing.
The velocity is in degrees per second along the Y axis of the pawn
bool Passer.Humanoid.HumanoidControl.isRemote = false |
Is true when this is a remote pawn.
Remote pawns are not controlled locally, but are controlled from another computer. These are copies of the pawn on that other computer and are updated via messages exchanges on a network.
|
get |
The neck height of the target rig.
When head tracking is used, this can be used to estimate the height of the player.