🏃Follow

Match or move towards a target transform

The Follow behavior provides a way to connect the transform of one object to another no matter where they are located in the scene hierarchy. This can be used to precisely match the position and rotation of the target object for virtual parenting, or to move an object towards another gradually over time to create chasing and flocking behavior.

To apply Follow, right-click an object in the Timeflow view and select:

Add Automation > Follow

Follow has just 1 read-only channel outputting the calculated final position in local coordinates.

Follow Editor

Select the object to view its settings in the Inspector.

For common features, please refer to Menu Bar and Update Settings.

Assign Target Object When Follow is first applied, it displays the warning icon to indicate that a target object must be assigned. Drag and drop a game object from the Hierarchy view into the field. Follow only functions when a target object is assigned, which may be any game object in the scene.

Follow Mode

Select the type of follow calculation to perform using the drop-down menu in the menu bar.

Note that additional settings may appear in the editor depending on the mode selected.

Direct

Performs an immediate match of the target object's transform.

Use Direct mode for virtual parenting. Objects from different positions in the scene hierarchy may be linked together spatially using Follow. This can be for the full duration of the scene or for specific periods of time.

Lerp

Performs a simple linear interpolation blended over time. Set Smooth Time (in seconds) to adjust how quickly the object reaches its target. A higher value results in slower following (lagging behind), while a smaller value more closely matches the target, with zero being directly on it.

Smooth Damp

Uses Unity's built-in method Vector3.SmoothDamp to interpolate following motion over time. Smooth Time (in seconds) determines the speed at which the object catches up to the target. This is an alterative to Lerp producing similar but different results.

Smooth Approach

This mode uses speed (units per second) rather than time to interpolate the follow movement. The object accelerates up to the Approach Speed (max velocity) and slows down exponentially as it nears the target.

Use Smooth Approach for fast following movement that slows down gracefully as it nears the object. The maximum approach speed is only reached when there is adequate distance to cover.

Lerp Local Axis

Applies linear interpolation on each transform axis separately. This is similar to Lerp above, however each axis has its own smoothing value for independent control.

Lerp Local Axis is useful to create stronger following action on one axis or another. This can be useful for objects that move in a line or on a plane relative to the target.

Physics

Applies movement using the physics engine. Rather than working with the object's transform, position and rotation are controlled by forces applied to the object's Rigidbody using one of the methods listed below.

Use Physics for dynamic interactive movement including collisions with other objects.

Physics Requires Runtime

Play Mode is required for physics to operate in Unity. The warning message displayed is just a reminder of this and may be dismissed.

Rigidbody Required

A Rigidbody component is required to use Physics. If the object doesn't have one, then the following warning is displayed. Click the Fix button to add one.

Force Mode

Select one of the built-in methods to apply movement to the rigidbody.

  • Force: Add a continuous force to the rigidbody, using its mass.

  • Acceleration: Add a continuous acceleration to the rigidbody, ignoring its mass.

  • Impulse: Add an instant force impulse to the rigidbody, using its mass.

  • VelocityChange: Add an instant velocity change to the rigidbody, ignoring its mass.

Using physics mode applies movement according to the collider and physical properties of the object. This can often be messy and lead to runaway objects and other interactions that make it difficult to predict or control. It may take some experimentation to find the right settings.

These are covered in more detail in the Unity documentation for ForceMode.

Editor Mode

Since physics doesn't operate in Edit Mode, this selects a fallback method for previewing the Follow behavior in the editor. This can be useful as a proxy or placeholder while editing animation.

Enter Play Mode to see final results.

The editor mode can only be a rough approximation since physics at runtime produces far more complex and unpredictable movement.

Follow Position

The object position is only modified if Follow Position is enabled.

Enable X | Y | Z

Enables each axis of the position separately.

If all axes are off, no position is applied.

Target Distance

Determines how close the following object may get to the target. As soon as the object reaches this distance from the target (from any direction), it stops or maintains that distance depending on the target movement.

Use the Target Distance to create a zone around the target that the following object won't cross into. This can be helpful to avoid intersecting objects or to create the effect of a force field around the target.

Target Offset

This applies an offset to the target position (in the target's local space) to attach the follower to a specific part or at a distance from the target.

Target Offset is useful for adjusting the alignment of a following object, especially when using Follow to virtually parent objects. The target offset is equivalent to the local position of a child of the target object.

Use Rigidbody

When enabled, movements are applied to the rigidbody component instead of the transform. This can be used with any follow mode. If Physics mode is selected, then movement is applied using forces, otherwise it is applied directly using MovePosition and MoveRotation.

Enable Use Rigidbody if the object needs to interact with colliders.

Use Rigidbody is required when using Physics mode.

Limit Position

If enabled, restricts object movement to stay within the world coordinates defined by min and max. Limits are only enforced for the checked axes. If all are unchecked, no limit is applied.

Use Limit Position to keep the object within scene bounds or any region needed. It can also be applied per axis to constrain objects to a plane or axis.

Limit Velocity

If enabled, the object is prevented from traveling faster than the max velocity (in units per second).

When using Physics mode this is enabled and controls the speed of the object.

Limit Velocity may affect each mode a little differently. It is best used with Smooth Damp or Physics.

Limit Distance

When enabled, Follow only moves if the target is further away than the minimum distance and closer than the maximum distance.

Use Limit Distance to make an object wait until the target object is within range and/or to stop following if the target is too close.

Rotation

Rotation Mode

  • None: Disables rotation entirely

  • Match Rotation: Sets the rotation to equal the target object rotation

  • Look At Object: Specify another game object to look at

  • Direction Of Movement: Object faces in the direction it is traveling

Enable X | Y | Z

Use these checkboxes to select which axes of rotation are applied. If all are unchecked, then no rotation is applied.

Limit Rotation

Enable this to set minimum and maximum rotation angles (defined as Euler angles).

Smooth Time

Applies temporal smoothing to rotation. Set to 0 to disable. Increasing the value has the effect of slowing down the object's rotation and applies to all rotation modes.

Orientation

Adds rotation overall to the object. Use this to further adjust the object's orientation.

Up Vector

This determines the upward direction of the object and defaults to (0, 1, 0). Any value may be entered however it is generally expected to be a normalized value (adding to 1) and representing a cardinal direction. For more info, refer to the Unity documentation for Vector3.

Start Position / Rotation

These options are only displayed when Position and Rotation are enabled respectively. The start position/rotation determines the placement of the object on initialization and looping.

Use a setting other than None for cases where objects need to begin with a specific placement. The object is reset to the specified position and/or rotation upon scene initialization and rewinding the timeline.

None

No start position/rotation is defined. This means that wherever the object is when this behavior becomes active is where it starts.

This mode is useful when Follow is taking over from another animation, or some other script is preparing object placements ahead of it. Otherwise beware that this mode may cause runaway objects that end up in different places each playback. For predictable and consistent results, use one of the other modes.

Original

Use this mode to store the starting position and rotation on startup. This assumes that the object placement is correct during OnAwake, which is only called once each load. If the timeline loops or rewinds, the object is restored to it's original position.

Set

Manually enter a specific position in local coordinates.

On Target

Use this mode to place the object on the target being followed.

This mode is useful when using Direct placement or anytime you want the following object to start at the same position as the target.

Close Gap

Forces an object towards the target or placement goal, with a value of 1 being on the target. When Close Gap is set to 0, it has no effect.

Close Gap is useful for forcing a lazy follower closer to the target object, all the way to the point that it is matching its transform. This is useful in animations to transition from an object approaching to being attached to the target.

Overall Blend

This is the final blend slider which controls the overall influence Follow has on the object.

Overall Blend is useful for smoothly reducing the intensity of follow movement all the way down to a standstill. This is also useful in reverse, transition from a stationary object to full follow motion.

Additional Notes

Rigidbody & Gravity

Follow does not work well with gravity since objects tend to fall and get stuck rather than move towards the target. Gravity is automatically disabled when a Rigidbody component is added to Follow, however it may be re-enabled as you wish. Objects are influenced by the same follow forces whether or not gravity is enabled, but the Max Velocity and the object's physical properties may need to be modified to get workable results.

While it is possible to use Channel Link with Follow, please note that Time Offset does not work since Follow is a simulation and not predeterminate. That is to say that Follow cannot calculate a correct position and rotation at any random time and only does so during playback. So any linked channels can only receive the current output value.

Last updated