- Home /
Movable Timeline of NavMeshAgent movement?
Basically, after determining the path of my agent Id like to be able to save its movement and be able to scrub through a slider/timeline forwarding and reversing its movement. How would I go about this?
I know I have an array of Vector3s from the agent path, I'm just having trouble on how I'd about about implementing the movement.
Answer by seant_unity · Mar 19, 2018 at 11:55 AM
There are a few options here, but the most straight forward approach is to create an animation clip from the path data you have.
You could use the GameObject Recorder (found here) to create an animation clip, or generate one yourself from the data.
Make sure the animation clip has 'Generate Root Motion Curves at Runtime' enabled. This is required to make it work correctly with timeline.
You can then manually create a timeline, or generate one from script as needed (see code below).
var timeline = ScriptableObject.CreateInstance<TimelineAsset>();
var track = timeline.CreateTrack<AnimationTrack>(null, null);
track.CreateClip(clip);
GetComponent<PlayableDirector>().playableAsset = timeline;
GetComponent<PlayableDirector>().SetGenericBinding(track, animator);
GetComponent<PlayableDirector>().Play();
So for this you would have to create the clips before hand right? Any suggestions for how Id go about this more dynamically? The destinations of my agents are randomly selected from an array of destinations.
You could write your own Track and Clip and control the transform itself. There is a look at track example in the Default Playable package on the Asset Store you could use as a starting point.
Please update the link to the GameObject recorder.
Your answer
Follow this Question
Related Questions
Can't get player to walk to object using NavMeshAgent 1 Answer
Root motion handled by script. How to still use root motion with disabled navmesh agent? 0 Answers
Animator controller stops canvas sprite code movement 0 Answers
Need tips on agent movement 1 Answer
Navmesh Agent Path Not Updating 1 Answer