I have a baked vertex animation that uses a list of transforms for positioning items placed on the head and hand. Those transforms are stored as global transforms.
The animation uses this list to set empties that hold things like hair, hats, guns, and boxes.
The animation works perfectly if it is not driven by my NavAgent, but I can’t figure out how to set those transforms local to allow AI navigation.
Here’s a video showing the problem.
im31wg
“man-parent-parent” holds the NavMeshAgent
“man-parent” holds root transforms
Here is my function. !CurrentAnimation.InPlace
works fine by setting the global position.
//check for in place animation
if (!CurrentAnimation.InPlace) {
//set positions
RootCurrentPosition = RootStartPosition + CurrentAnimation.Transforms[CurrentFrame].RootPosition[AnimStartRotation] * Scale;
if (Enabled) {
//root
Root.position = RootCurrentPosition;
Root.rotation = CurrentAnimation.Transforms[CurrentFrame].RootRotation[AnimStartRotation];
//head
if (HeadTransformEnabled) {
HeadCurrentPosition = RootStartPosition + CurrentAnimation.Transforms[CurrentFrame].HeadPosition[AnimStartRotation] * Scale;
Head.position = HeadCurrentPosition;
Head.rotation = CurrentAnimation.Transforms[CurrentFrame].HeadRotation[AnimStartRotation];
}
}
} else {
//set positions
RootCurrentPosition = Root.parent.position + CurrentAnimation.Transforms[CurrentFrame].RootPosition[0] * Scale;
if (Enabled) {
//root
Root.localPosition = Root.parent.InverseTransformPoint(RootCurrentPosition);
Root.rotation = CurrentAnimation.Transforms[CurrentFrame].RootRotation[0] * Root.parent.rotation;
//head
if (HeadTransformEnabled) {
HeadCurrentPosition = Root.parent.position + CurrentAnimation.Transforms[CurrentFrame].HeadPosition[0] * Scale;
Head.localPosition = Root.InverseTransformPoint(HeadCurrentPosition);
Head.rotation = CurrentAnimation.Transforms[CurrentFrame].HeadRotation[0] * Root.parent.rotation;
}
}
}
This is the function that saves the transforms. rot
indexes the movements in 4 directions. For “In Place” animations I use the 0 index as there’s no reason to save the other indices.
Transforms[frame].RootPosition[rot] = Root.transform.position;
Transforms[frame].RootRotation[rot] = Root.transform.rotation;
Transforms[frame].HeadPosition[rot] = Head.transform.position;
Transforms[frame].HeadRotation[rot] = Head.transform.rotation;
Transforms[frame].HandPosition[rot] = Hand.transform.position;
Transforms[frame].HandRotation[rot] = Hand.transform.rotation;
RotationInt[rot] = (int)SetRotation(Root.transform.rotation.eulerAngles.y, 0) / 90;