I’m doing a behavior planning system, and i need to be able to predict the distance traveled during an animation clip. Is it possible to somehow do a projection of the animation clip start frame and end frame in order to calculate the distance between the two?
In your case you should use it with AvatarTarget.Root and 1.0f since you want to know the distance for one full animation loop, you can set a target further in time also like 4.0f which mean 4 full animation loop.
animator.SetTarget(AvatarTarget.Root, 1.0f);
Also you need to wait at least one update frame for your animator to compute the target, so you can setup your target in a MonoBehaviour.Update() and then retrieve the result with either MonoBehaviour.LateUpdate() on the same frame or wait one more frame and get the result in the next MonoBehaviour.Update() call.
I actually tried using SetTarget() and targetPosition but i need to calculate a whole path of animation clip distances before the character even moves. The idea is to plan a path with an a* search algorithm using the distance traveled in each clip as their cost to evaluate the shortest distance. Therefore it would be preferred to calculate the projection of the animation clips from start to end frame before any movement occurs so the path can be created beforehand. So I guess what I am asking is if it is possible to get information about the distance and orientation of the last frame of an arbitrary animation clip relative to the start frame without actually running the animations?
For this you would need to sample by your self your animation clip at both time and compute the distance and orientation.
The reason why SetTarget need at least one evaluation is because the final result depend on the controller’s parameter value. By example if you call SetTarget while your controller current state is a blend tree with many clip, to compute the target position when need to evaluate the whole blend tree.