Documentation

Unity Engine

Download Unity

Unity Engine

ProjectRootTranslation(float3, quaternion, bool)

Projects a root translation onto the ground, which is the horizontal plane at y = 0.
Read time 2 minutesLast updated 4 hours ago

Definition

public static float3 ProjectRootTranslation(float3 translation, quaternion rotation, bool bankPivot)

Parameters

translation

The root translation to project onto the ground.

rotation

The root rotation. When
bankPivot
is
true
, its up axis is the projection direction.

bankPivot

Whether to project along the up axis of
rotation
instead of downward.

Returns

Type

Description

float3The projected translation, with a y value of 0.

Remarks

Use this method to find the ground position of a bone when you match clips during a transition. The bone doesn't have to be the top of the hierarchy. For example, project the hips to align a walk clip with a jog clip.
If
bankPivot
is
false
, the method projects the translation straight down and ignores the rotation of the bone. If it is
true
, the method takes the rotation into account and projects the translation along the up axis of
rotation
, unless that axis is horizontal. A horizontal axis makes the projection impossible, so the method projects downward instead.
The following example uses the
Unity.Animations
and
Unity.Mathematics
namespaces. It projects the hips of a walk clip and a jog clip onto the ground, then computes the offset that aligns the jog with the walk.

Examples

// This example aligns a jog clip with a walk clip during a transition, using the hips as the matching bone.// It returns the horizontal offset to add to the jog so that the jog hips are above the same ground position// as the walk hips.public static float3 ComputeAlignmentOffset( float3 walkHipsTranslation, quaternion walkHipsRotation, float3 jogHipsTranslation, quaternion jogHipsRotation, bool bankPivot){ // Project the hips of each clip onto the ground. With bankPivot set to true, the projection follows the up // axis of the hips rotation, so tilted hips shift the ground position horizontally. With bankPivot set to // false, the projection goes straight down. float3 walkGroundPosition = RootMotionUtility.ProjectRootTranslation(walkHipsTranslation, walkHipsRotation, bankPivot); float3 jogGroundPosition = RootMotionUtility.ProjectRootTranslation(jogHipsTranslation, jogHipsRotation, bankPivot); // Both ground positions are on the ground plane, so the offset is horizontal. return walkGroundPosition - jogGroundPosition;}