đĸMotion Path
Animate objects in 3d with a Bezier path and velocity curve
Use Motion Path to animate objects in 3D space with advanced curve editing features to take full control over an object's position, rotation, and velocity over time.
Avoid using on objects with an Animator component
Whenever a Motion Path is applied to a game object with an Animator component, a warning will be displayed. It is strongly suggested to apply the motion path on a parent object instead, otherwise it may conflict with the animation applied by Animator. This is especially true with character animations or anything that applies root motion. You may choose to ignore this warning if there is no immediate conflict.
Motion Path initially exposes 1 channel, Path Position, and may optionally expose Path Rotation and Velocity channels.
When a new Motion Path is created, a start and end keyframe are added automatically starting at the current time. This is to help get started though these keyframes may be changed or deleted.
Motion Path requires at least 2 keyframes to interpolate. If only 1 keyframe is present, then the object holds at that position. If all keyframes are removed from the channel, then the Motion Path behavior has no effect on the object.
Velocity Curves
Path Position is a special type of channel combining position and velocity in one. Each keyframe relates to a node on the path and also determines velocity over time.
To edit the path velocity, select Path Position and switch to the Graph View.
This curve displays relative velocity from one keyframe to the next. Each keyframe Value (as seen in the Info Panel) is the total average velocity from one keyframe to the next and is automatically calculated based on its distance and time from the previous keyframe.
Note that the Path Position velocity curve is relative, not absolute. To work with the final computed velocity of an object, see Velocity Channel.
Velocity Calculation
When moving a keyframe in time you'll notice that the curve and velocity values automatically adapt due to the mathematical constraints of the formulae shown below.
Velocity is calculated between two keyframes A and B as follows:
velocity = Distance(A.position, B.position) / (B.time - A.time)
Or in simpler terms:
velocity = distance / seconds
(i.e. units per second)
The curve between keyframes then determines how the velocity is distributed over time. Since the total average velocity must add up to cover the distance over time, speeding up one half of the curve requires slowing down the other half.
The velocity graph naturally trends upwards from left to right and is cumulative over the path length. This means it is impossible to place a keyframe lower on the graph than the preceding one, since the distance between nodes is always a positive value.
If 2 keyframes have the same position (and the tangents are zero), the velocity curve between them is flat since there is nothing interpolate.
Velocity Curve Examples
Following are some examples to illustrate how velocity curves behave.
Refer to the Graph View documentation for more curve editing features.
For alternate methods of animating objects along a Motion Path, see Place On Path.
Motion Path Editor
Select the object to view its settings in the Inspector.
For common features, see Menu Bar and Update Settings.
Interpolation
Interpolation Mode
Select one of the following path interpolation modes.
Hold: The path does not interpolate and the object remains fixed at each keyframe position.
Linear: Interpolates in a straight line from one position keyframe to the next.
Bezier: Full curve editing features with 3D Bezier tangents.
Note that the path Interpolation Mode applies only to the path in 3D space and is separate from the velocity curve interpolation shown in the Graph View.
Close Path
If enabled, the path is forced to be a closed shape. Use this for circular and looping paths.
A closed path requires at least 3 keyframes. Also it is important to be aware that the first and last keyframe in the path become tied together and changing one affects the other.
To create a closed path, it is recommended to first set at least 3 keyframes and arrange them in the shape generally desired in the Scene View. Add more keyframes if needed. Before enabling Close Path make sure the start and end keyframes are near each other. The end keyframe snaps to the start keyframe once Close Path is enabled.
Rotation Mode
Select one of the following modes to determine how rotation is calculated:
None: No rotation is calculated. Use this mode to animate rotation separately.
Interpolate: Interpolates the rotations of each keyframe node.
Look Ahead: Automatically rotates by looking ahead on the path.
Use Interpolate to control the object's rotation using the rotation of each keyframe node. When this mode is selected, the rotation of each node may be set using the rotate tool in the Scene View, or entered numerically in the Info Panel for selected keys.
Look Ahead Time
Sets the time in seconds to look ahead on the path for Look Ahead interpolation.
Use Look Ahead for easier setup. Using this mode, the object faces the direction of travel automatically and requires less work than setting rotation for each node manually.
For additional control over an object's rotation, insert an extra transform in the hierarchy to add offsets and/or animate using any behavior or method desired.
Expose Target Object
When using Look Ahead, enable this option to expose the look target in the hierarchy view as a game object. This object is managed by Motion Path and should not be deleted or moved.
Please keep the look target object under same parent as the motion path object, otherwise any inherited transforms could break the look at calculation and produce unexpected results.
The main reason to expose the look target is to use it for other calculations or behaviors. For example, it could be used as the look target for other objects, or an object could be placed at the look position by making it a child or connecting it using Channel Link.
Up Vector
This settings only applies to Look Ahead rotation and determines the upward direction of the object for the look at calculation. This expects a normalized value (adding up to 1) defining a cardinal direction. Usually this value is (0, 1, 0) though may be changed if the object is oriented on a different plane.
See the Unity documentation on Vector3.
Orientation
Adds rotation in Euler angles to the object overall. Use this to orient the object. The property may also be animated to apply additional rotation to that already calculated by the motion path.
Other ways of animating rotation
An alternative to the rotation modes above is to use a separate behavior or animation channel. Object rotation can be animated independently using a standard animation channel or a behavior such as Auto Rotate .
To use an alternate method, make sure to set the Rotation Mode to None.
Auto Tangent Ratio
Controls how 3D Bezier tangents are calculated for keyframes using Auto Calculate. The slider represents the tangent lengths relative to its neighboring nodes. This affects the degree of curving with a value of 0 being linear (no tangent length) and a value of 1 being maximum tangent length.
The ratio is multiplied with the Weight value of each node, so you may adjust the degree of bending on a per-keyframe basis. See the Motion Path Nodes section below.
Enable Auto Update for keyframe nodes to automatically recalculate tangents
This only affects keyframes set to Auto Calculate mode, which can be set in the Scene View or in the node details.
Position Smoothing
Applies temporal smoothing to the position based on time in seconds. Use this to create smoother object motions, when adhering to the path is not as important.
Position Smoothing dampens the movement of the object using a time delay, causing it to round corners and has a softening/reducing effect on the curve overall.
For strict adherence to the path, disable Position Smoothing and only adjust the keyframes and velocity curve to smooth out the motion.
Rotation Smoothing
Applies temporal smoothing to rotation over time in seconds.
Rotation Smoothing delays an object's rotation. Larger values may cause the rotation to lag behind the path's rotation.
The smoothing features require continuous play to calculate properly. When jumping or skipping in time, the calculation feature will not be accurate until it is given sufficient time playing uninterrupted. To view the results of smoothing, simply play the Timeflow view.
Motion Path Nodes
The Nodes section displays a list of all keyframe nodes on the path.
Expand / Collapse
Each node may be expanded using the foldout arrow on the left to further edit specific details. Use the buttons Expand All and Collapse All to open or close details for all nodes.
To help facilitate keyframe editing, each node is automatically expanded and highlighted in the inspector when keyframes are selected in either the scene or Timeflow views.
Expose Nodes
Each keyframe on a motion path is associated with a node object. These are objects are hidden from the hierarchy view by default to reduce clutter in the project, however may be revealed for additional uses or direct editing of the game objects.
By using game objects to represent nodes on a motion path, more advanced features are possible and makes path nodes easily accessed by other scripts. Objects may also be placed relative to nodes on a path, and nodes can be used to influence other behaviors. Nodes can be hidden again at any time by unchecking Expose Nodes. Also see Place On Path for another way to place objects relative to a path or node.
Beware of making objects children of nodes
Although it is not prohibited, it is advised against using nodes as the parent for any other objects in the scene. Doing so my result in objects being deleted if keyframes are removed. An alternative is to use Follow to link a game object position to a node.
When nodes are exposed in the hierarchy, selecting one or more objects shows its details in the inspector. These are the same parameters shown in the Nodes section above, however this method supports multi-object editing so you can change attributes multiple nodes at once.
The motion path automatically detects changes to position and rotation as long as Timeflow is not playing. Changes may be applied directly by editing the fields in the inspector for one or multiple objects.
Note that if you use the move and rotate tools on a selected node object in the scene view, the selection reverts back to the Motion Path for full editing features.
Locking Nodes
Each keyframe node may be locked in time and/or value to prevent changes to it. To lock all keyframes at once, use the Lock All and Unlock All buttons.
Keyframe nodes may also be locked/unlocked in the Scene View and Timeflow view.
Clear All
Deletes all keyframes and nodes from the path.
Expose ID
This makes a keyframe node accessible to other scripts to set its value remotely. This is an advanced scripting feature only used for special setups where a motion path is modified by a custom script. For more about this feature, please see the documentation for Exposed Keyframes.
Tools & Options
Show Gizmos
Enable this to display the 3D path and editing tools in the Scene View. The color may be set independently from the channel color and may be adjusted as preferred.
Stay Visible
If enabled, the path remains visible in the Scene View even when the object is not selected. Otherwise, the path and gizmos are only displayed when the object is the active selection.
This setting only affects the visibility of the path. The editing controls are only ever displayed when the motion path or one of its nodes are selected.
Can Edit
This enables the motion path editing tools displayed in the Scene View. See the Gizmos / Scene View section below for further information.
Rotation Channel
Enable this to expose the object rotation as a separate read-only channel. This outputs the final rotation of the object which may be used with Channel Link to drive other behaviors.
Velocity Channel
Enable to expose a separate read-only velocity channel outputting the final velocity of the object. This is not to be confused with the relative velocity curve in the Path Position channel.
Vector: velocity as a Vector3
Speed: velocity in units per second (vector length)
Interpolation: current path interpolation from 0-1 over full length of path
Read-Only at Current Time
Rotation and Velocity channels are read-only. Their values are processed at the same time as the main motion path channel. These channels may be used with Channel Link however they do not support time offsets, only values at the current time.
Bounding Frames
This is an editor tool for visualization and scene construction. When enabled, square bracket shapes are drawn along the path in the Scene View.
Bounding frames are a helpful visual aid to see the shape of the path in 3D and to identify any issues with velocity and rotation.
The default settings display rectangles along the path, enabled by Draw Rectangles. Adjust the Size and Count as desired.
The frames are spaced according to the path velocity if Use Velocity is enabled, otherwise they are spaced evenly over the distance of the path. Adjust the Start and End to limit the frames to a specific part of the path.
Prefab & Generate Objects
Any game object or prefab may be replicated along the path. When an object is assigned, mesh instances are drawn in the Scene View as a preview however the objects are not visible in the camera until generated as game objects.
Bounding Frames are only displayed in the Scene View and are not visible in the camera unless they are generated into game objects using the Generate Objects button.
Once objects are generated, they are no longer referenced or managed by the motion path and may be altered, moved, or deleted as you wish.
Notify On Setup
This is both an editor and runtime feature to notify other components when the motion path has been setup or modified. This is particularly useful to update other behaviors that base their positioning on the path, such as when using Follow or Place On Path.
Gizmos / Scene View
Additional path editing tools are displayed in the Scene View while the object is selected.
Make sure to enable Show Gizmos and Can Edit and also that Gizmos are enabled in the Scene View.
Keyframe Selection
Each keyframe node is displayed as a yellow dot. Click on a keyframe to select it. The selected key is displayed with a movable position handle, which can also be rotated by switching to the Rotate tool in the Unity toolbar.
When viewing the motion path in the Scene View and in Timeflow at the same time, selecting a keyframe in either view selects it in the other.
Select multiple keyframes by holding the Shift key while clicking.
Double-click a keyframe to select it and jump to its time in the Timeflow view.
Add Key
Click to insert a new keyframe at the current time.
This button is disabled if there is already a keyframe at the current time.
Prev / Next
Selects the next or previous keyframe. Use this to iterate through the keyframe nodes.
Select
Use this menu to select all nodes, deselect all, or select the first or last node.
Lock / Unlock
Click the lock icon to toggle the locked state of the currently selected keyframes. Locked keyframes are displayed with a small lock next to them.
Locked keyframes can still be selected but not moved or modified.
Tangents
When using Bezier interpolation, each selected keyframe displays tangent handles to edit the shape of the curve. Click and drag on the tangent handles to modify them.
Auto Calculate
Keyframes may be set to auto calculate tangents which approximates handles based on its position relative to the neighboring nodes.
Auto Calculate performs an educated guess at the shape desired, however it is unavoidable that it will sometimes produce undesired results. This mode works best for intermediate keyframes and can be helpful when creating a path to get the approximate shape before manually fine tuning each keyframe.
Auto Calculate is turned off automatically for any keyframe as soon as any direct modification is made to its tangents.
Enable Tangent Auto Update to continuously update keyframes with Auto Calculate enabled. This results in a flexible path that dynamically adapts to changes.
To auto calculate tangents just once without enabling Auto Calculate mode, use the Tangent menu command Expand.
Break / Unify
By default tangents are unified, meaning that adjusting one side affects the other and they remain connected in a straight line. However tangents may be broken to independently edit each side.
Collapse
This command sets the tangents to 0 length resulting in a hard angle. This can be used to make keyframe nodes linear rather than curved.
Expand
Automatically calculates tangents based on the keyframe position relative to other nodes.
Show / Hide
Use these commands to show and hide the tangent controls for selected keyframes. This has no effect on the shape of the path and simply determines whether the UI controls are displayed.
Once tangents have been set for keyframes, you may want to hide them to prevent further changes without first showing them again.
Flatten
Use these options to set tangents to zero, flattening them on the specified plane.
Delete Node
Deletes the selected keyframe nodes. This has the same effect as deleting keyframes in the Timeflow view or Inspector.
Additional Notes
Broken Path?
At some point you may encounter a situation where the path in the scene view flattens out or has a linear segment that doesn't make sense and appears to be broken.
This is a result of the velocity curve shown below. This can happen after inserting a new keyframe and requires adjusting the tangents and keyframe timing to balance out the curve.
Once the kinks in the velocity curve have been smoothed out, the 3D curve appears correctly.
Last updated