Humanoid Control for Unity v4
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Properties | Events | List of all members
Passer.Humanoid.HumanoidControl Class Reference

Description

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

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:

Input

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.

Animator

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 Animations.

Pose

This will set the base pose of the avatar. For more information see Pose.

Networking

Remote Avatar

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.

Movement

This sets a number of parameters for the locomotion of the avatar:

Settings

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

void ChangeAvatar (GameObject fpAvatarPrefab)
 
void ChangeAvatar (GameObject fpAvatarPrefab, GameObject tpAvatarPrefab)
 
void LocalChangeAvatar (GameObject avatarPrefab)
 
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 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 More...
 
HumanoidTarget.TargetedBone GetBone (Side side, SideBone sideBoneId)
 Get the Humanoid Bone on the incated side of the humanoid More...
 
void ScaleTrackingToAvatar ()
 
void AdjustTracking (Vector3 translation)
 Adjust the tracking origin of all trackers More...
 
void AdjustTracking (Vector3 translation, Quaternion rotation)
 Adjust the tracking origin of all trackers More...
 
void RetrieveBones ()
 Scans the humanoid to retrieve all bones
 
void OnApplicationQuit ()
 
delegate void OnNewNeckHeight (float neckHeight)
 
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 More...
 
void MoveSideward (float x)
 Moves the humanoid sideward More...
 
virtual void Move (Vector2 velocity)
 Moves the humanoid in 2D space More...
 
virtual void Move (Vector3 velocity)
 Moves the humanoid
 
void MoveWorldVector (Vector3 v)
 
void Stop ()
 
void Rotate (float angularSpeed)
 Rotate the humanoid More...
 
void Rotation (float yAngle)
 Set the rotation angle along the Y axis
 
void Dash (Vector3 targetPosition)
 Quickly moves this humanoid to the given position More...
 
void Teleport (Vector3 targetPosition)
 Teleports this humanoid to the given position More...
 
void TeleportForward (float distance=1)
 Teleports the humanoid in the forward direction More...
 
void MoveTo (Vector3 position, MovementType movementType=MovementType.Teleport)
 Moves the humanoid to the given position More...
 
IEnumerator RotateTo (Quaternion targetRotation)
 Rotation animation to reach the given rotation More...
 
IEnumerator LookAt (Vector3 targetPosition)
 Rotation animation to look at the given position More...
 
IEnumerator WalkTo (Vector3 targetPosition)
 Movement animation to reach the given position More...
 
IEnumerator WalkTo (Vector3 targetPosition, Quaternion targetRotation)
 Movement animation to reach the given position and rotation More...
 
void Jump (float takeoffVelocity)
 Lets the Humanoid jump up with the given take off velocity More...
 
Vector3 CheckMovement ()
 
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 More...
 
delegate void OnNewHumanoid (HumanoidControl humanoid)
 
bool IsVisible (Camera camera)
 Is this humanoid visible in the given camera? More...
 

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 More...
 
static GameObject FindTrackerObject (GameObject realWorld, string trackerName)
 Tries to find a tracker GameObject by name More...
 
static HumanoidControl[] AllVisibleHumanoids (Camera camera)
 Returns all humanoid which are in the frustum of the camera More...
 

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 More...
 
bool showTargetRig = false
 Draws the target rig in the scene view
 
Animator avatarRig
 The avatar Rig More...
 
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 More...
 
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 More...
 
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 More...
 
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 More...
 
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 More...
 
bool useLegLengthCorrection = false
 
bool floatCorrection = false
 Correct floating avatars when user is taller than the avatar
 
string animatorParameterForward
 
string animatorParameterSideward
 
string animatorParameterRotation
 
string animatorParameterHeight
 
int animatorParameterForwardIndex
 
int animatorParameterSidewardIndex
 
int animatorParameterRotationIndex
 
int animatorParameterHeightIndex
 
bool isRemote = false
 Is true when this is a remote pawn More...
 
ulong nwId
 The Id of this pawn across the network
 
int id = -1
 The local Id of this humanoid
 

Protected Member Functions

void Awake ()
 
void NewTargetComponents ()
 
void StartTargets ()
 Start the targets for this humanoid
 
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 More...
 
void Update ()
 
void FixedUpdate ()
 
void LateUpdate ()
 
virtual void UpdatePose ()
 
virtual void UpdatePoseEvent ()
 
void CalculateMovement ()
 
void CheckGround ()
 
void CheckGrounded ()
 
void CheckGroundMovement ()
 
virtual void CheckBodyPull ()
 
void KinematicBodyControlOneHanded (HandTarget handTarget)
 
void KinematicBodyControlTwoHanded ()
 
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
 
Vector3 gravitationalVelocity
 
Vector3 inputMovement = Vector3.zero
 
Transform lastGround
 
Vector3 lastGroundPosition = Vector3.zero
 
float lastGroundAngle = 0
 

Properties

float trackingNeckHeight [get]
 The neck height of the target rig More...
 
bool showSkeletons [getset]
 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.
 

Events

OnNewNeckHeight OnNewNeckHeightEvent
 
OnHumanoidPose onHumanoidPose
 
static OnNewHumanoid onNewHumanoid
 Event triggered when a new humanoid enters the current scene
 

Member Enumeration Documentation

◆ ScalingType

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.

Member Function Documentation

◆ GetBone() [1/2]

HumanoidTarget.TargetedBone Passer.Humanoid.HumanoidControl.GetBone ( Bone  boneId)

Get the Humanoid Bone

Parameters
boneIdThe identification of the requested bone

◆ GetBone() [2/2]

HumanoidTarget.TargetedBone Passer.Humanoid.HumanoidControl.GetBone ( Side  side,
SideBone  sideBoneId 
)

Get the Humanoid Bone on the incated side of the humanoid

Parameters
sideThe requested side of the humanoid
sideBoneIdThe identification of the requested bone

◆ SetTrackingHeightToAvatar()

void Passer.Humanoid.HumanoidControl.SetTrackingHeightToAvatar ( )
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.

◆ AdjustTracking() [1/2]

void Passer.Humanoid.HumanoidControl.AdjustTracking ( Vector3  translation)

Adjust the tracking origin of all trackers

Parameters
translationThe translation to apply to the tracking origin

◆ AdjustTracking() [2/2]

void Passer.Humanoid.HumanoidControl.AdjustTracking ( Vector3  translation,
Quaternion  rotation 
)

Adjust the tracking origin of all trackers

Parameters
translationThe translation to apply to the tracking origin
rotationThe rotation to apply to the tracking origin

◆ MoveForward()

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

Parameters
zThe distance in units(meters) to move forward.

◆ MoveSideward()

void Passer.Humanoid.HumanoidControl.MoveSideward ( float  x)

Moves the humanoid sideward

Parameters
xThe distance in units(meters) to move sideward.

◆ Move()

virtual void Passer.Humanoid.HumanoidControl.Move ( Vector2  velocity)
virtual

Moves the humanoid in 2D space

Parameters
velocityThe velocity to move with

The velocity axis are mapped as follows: x = left/right movement y = forward/backward movement

◆ Rotate()

void Passer.Humanoid.HumanoidControl.Rotate ( float  angularSpeed)

Rotate the humanoid

Rotates the humanoid along the Y axis

Parameters
angularSpeedThe speed in degrees per second

◆ Dash()

void Passer.Humanoid.HumanoidControl.Dash ( Vector3  targetPosition)

Quickly moves this humanoid to the given position

Parameters
targetPositionThe position to move to

◆ Teleport()

void Passer.Humanoid.HumanoidControl.Teleport ( Vector3  targetPosition)

Teleports this humanoid to the given position

Parameters
targetPositionThe position to move to

◆ TeleportForward()

void Passer.Humanoid.HumanoidControl.TeleportForward ( float  distance = 1)

Teleports the humanoid in the forward direction

Parameters
distanceThe distance to teleport

The forward direction is determined by the hips target forward.

◆ MoveTo()

void Passer.Humanoid.HumanoidControl.MoveTo ( Vector3  position,
MovementType  movementType = MovementType.Teleport 
)

Moves the humanoid to the given position

Parameters
movementTypeThe type of movement to use

◆ RotateTo()

IEnumerator Passer.Humanoid.HumanoidControl.RotateTo ( Quaternion  targetRotation)

Rotation animation to reach the given rotation

The speed of the rotation is determined by the rotationSpeed

Parameters
targetRotationThe target rotation

◆ LookAt()

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

Parameters
targetPositionThe position to look at
Returns

◆ WalkTo() [1/2]

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

Parameters
targetPositionThe position to where the pawn should walk
Returns

◆ WalkTo() [2/2]

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

Parameters
targetPositionThe position to where the pawn should walk
targetRotationThe rotation the pawn should have at the end
Returns

◆ Jump()

void Passer.Humanoid.HumanoidControl.Jump ( float  takeoffVelocity)

Lets the Humanoid jump up with the given take off velocity

Parameters
takeoffVelocityThe vertical velocity to start the jump

◆ GetRealWorld()

static GameObject Passer.Humanoid.HumanoidControl.GetRealWorld ( Transform  transform)
static

Gets the Real World GameObject for this Humanoid

Parameters
transformThe root transform of the humanoid

◆ FindTrackerObject()

static GameObject Passer.Humanoid.HumanoidControl.FindTrackerObject ( GameObject  realWorld,
string  trackerName 
)
static

Tries to find a tracker GameObject by name

Parameters
realWorldThe Real World GameOject in which the tracker should be
trackerNameThe name of the tracker GameObject to find

◆ GetHumanoidPosition()

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

Returns
The position of the humanoid

◆ AllVisibleHumanoids()

static HumanoidControl[] Passer.Humanoid.HumanoidControl.AllVisibleHumanoids ( Camera  camera)
static

Returns all humanoid which are in the frustum of the camera

Parameters
cameraThe camera in which the humanoids should be visible
Returns
An array of all visible humanoids

◆ IsVisible()

bool Passer.Humanoid.HumanoidControl.IsVisible ( Camera  camera)

Is this humanoid visible in the given camera?

Parameters
cameraThe camera in which the humaonid may be visible
Returns
true when the humanoid is visible in the camera

Member Data Documentation

◆ targetsRig

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

◆ avatarRig

Animator Passer.Humanoid.HumanoidControl.avatarRig

The avatar Rig

This is the rig of the avatar we want to control.

◆ calculateBodyPose

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.

◆ playerType

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

◆ unityXR

UnityXRTracker Passer.Humanoid.HumanoidControl.unityXR = new UnityXRTracker()

The Unity XR tracker

\

◆ ground

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

◆ groundAngularVelocity

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

◆ isRemote

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.

Property Documentation

◆ trackingNeckHeight

float Passer.Humanoid.HumanoidControl.trackingNeckHeight
get

The neck height of the target rig

When head tracking is used, this can be used to estimate the height of the player.


The documentation for this class was generated from the following file: