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
- Type: Method
- Namespace: Unity.Animations
- Assembly: UnityEngine.AnimationCoreModule
public static float3 ProjectRootTranslation(float3 translation, quaternion rotation, bool bankPivot)
Parameters
The root translation to project onto the ground.
The root rotation. When is , its up axis is the projection direction.
bankPivottrueWhether to project along the up axis of instead of downward.
rotationReturns
Type | Description |
|---|---|
| float3 | The 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 is , the method projects the translation straight down and ignores the rotation of the bone. If it is , the method takes the rotation into account and projects the translation along the up axis of , unless that axis is horizontal. A horizontal axis makes the projection impossible, so the method projects downward instead.
bankPivotfalsetruerotationThe following example uses the and 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.
Unity.AnimationsUnity.MathematicsExamples
// 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;}