# Follow

{% embed url="<https://youtu.be/EsR5h43vzrs>" %}

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.

{% hint style="success" %}
To apply Follow, right-click an object in the Timeflow view and select:

#### Add Automation > Follow

{% endhint %}

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

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FAaS7lQDBgvEV6HUlO8BS%2Fimage.png?alt=media&#x26;token=d5b96385-64d5-492c-8021-3a5c9eccfbcf" alt=""><figcaption></figcaption></figure>

## Follow Editor

Select the object to view its settings in the Inspector.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FrlhOQ6xItlGqEY6fPD2n%2Fimage.png?alt=media&#x26;token=48491502-09ad-4e34-9af1-831f550a5f50" alt=""><figcaption><p>Default settings when Follow is first applied.</p></figcaption></figure>

For common features, please refer to [Menu Bar](https://axongenesis.gitbook.io/timeflow/user-guide/timeflow-editor/menu-bar) and [Update Settings](https://axongenesis.gitbook.io/timeflow/user-guide/timeflow-editor/update-settings).

{% hint style="warning" %}
**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.
{% endhint %}

## Follow Mode

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

<div align="left"><figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2F7IOpHuifALSJfn8PjfGt%2Fimage.png?alt=media&#x26;token=31c8c8ce-71bf-4d67-a1d7-f91bc5494b3c" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
Note that additional settings may appear in the editor depending on the mode selected.
{% endhint %}

### Direct

Performs an immediate match of the target object's transform.&#x20;

{% hint style="success" %}
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.
{% endhint %}

### 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.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FTyKJurZW4Hpjt6UhgPAO%2Fimage.png?alt=media&#x26;token=b2e056a5-5273-44c7-b0ae-1434b0e7b8e8" alt=""><figcaption></figcaption></figure>

### Smooth Damp

Uses Unity's built-in method [Vector3.SmoothDamp](https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html) 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.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FbFiiZlAt4JNpcpMaoWWb%2Fimage.png?alt=media&#x26;token=f1b0acf0-4eca-4f62-83e0-d89d9941fa11" alt=""><figcaption></figcaption></figure>

### 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.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FMYLRD6jn02uzGYETFyXt%2Fimage.png?alt=media&#x26;token=11f2b9c5-24f0-42fd-a2f8-0d3991673a69" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
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. &#x20;
{% endhint %}

### 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.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FvGcPRqV5jDn4paUNq7B7%2Fimage.png?alt=media&#x26;token=d659bbc6-044e-48a4-9fe0-9a823cca0783" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
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.
{% endhint %}

### 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.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FzpWLGKbaQUSOILNYJVu2%2Fimage.png?alt=media&#x26;token=148448b0-3abd-45c4-a2a4-b2a67843a33a" alt=""><figcaption><p>Rotation Force is only displayed if Rotation Mode is other than none.</p></figcaption></figure>

{% hint style="success" %}
Use Physics for dynamic interactive movement including collisions with other objects.&#x20;
{% endhint %}

{% hint style="warning" %}
**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.&#x20;
{% endhint %}

{% hint style="warning" %}
**Rigidbody Required**

A [Rigidbody ](https://docs.unity3d.com/Manual/class-Rigidbody.html)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.

![](https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FAau2kxzES0eJUJIRxBIe%2Fimage.png?alt=media\&token=a270e4ea-425e-4565-8300-298aef9689d2)
{% endhint %}

## Force Mode

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

![](https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2F4XeljYdbEvLX8i7wRY5F%2Fimage.png?alt=media\&token=2daee855-fd3a-4f91-8daf-e57cbf0fecb7)

* **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.&#x20;
* **VelocityChange:** Add an instant velocity change to the rigidbody, ignoring its mass.<br>

{% hint style="info" %}
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.
{% endhint %}

These are covered in more detail in the Unity documentation for [ForceMode](https://docs.unity3d.com/ScriptReference/ForceMode.html).&#x20;

### 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.

{% hint style="warning" %}
**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.&#x20;
{% endhint %}

## Follow Position

The object position is only modified if Follow Position is enabled.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2F4TXSKUOB7Q4WB638Nv2f%2Fimage.png?alt=media&#x26;token=c29994e0-b152-43a3-a919-834d0aacc30c" alt=""><figcaption></figcaption></figure>

### Enable X | Y | Z

Enables each axis of the position separately.

{% hint style="warning" %}
If all axes are off, no position is applied.
{% endhint %}

### 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.

{% hint style="success" %}
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.
{% endhint %}

### 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.

{% hint style="success" %}
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.
{% endhint %}

### 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 ](#physics)mode is selected, then movement is applied using forces, otherwise it is applied directly using [MovePosition](https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html) and [MoveRotation](https://docs.unity3d.com/ScriptReference/Rigidbody.MoveRotation.html).&#x20;

{% hint style="success" %}
Enable Use Rigidbody if the object needs to interact with colliders.
{% endhint %}

{% hint style="warning" %}
Use Rigidbody is required when using [Physics](#physics) mode.
{% endhint %}

### 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.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FYSnAtR1vjxY79MCNBfwf%2Fimage.png?alt=media&#x26;token=aa045388-0ef3-43e9-a2ff-9e5fe661a6a4" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
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.
{% endhint %}

### Limit Velocity

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

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2F3p5BZtZW9CYhXkDPvvJF%2Fimage.png?alt=media&#x26;token=7fbb1abb-7e45-4b68-9836-0ddafb690a4a" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
When using Physics mode this is enabled and controls the speed of the object.&#x20;
{% endhint %}

{% hint style="info" %}
Limit Velocity may affect each mode a little differently. It is best used with [Smooth Damp](#smooth-damp) or [Physics](#physics).
{% endhint %}

### Limit Distance

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

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FmksvKERxnm6IjfENQEwI%2Fimage.png?alt=media&#x26;token=2d5646b6-3929-4738-b62c-45a00140e256" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
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.
{% endhint %}

## Rotation

### Rotation Mode

![](https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FjbPsFuKbypKXnLpb661y%2Fimage.png?alt=media\&token=9f5f3cb9-8ee0-4d48-82b7-ce1c86a1476a)

* **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

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FcpYHM1C2fh5IBCXPpbKs%2Fimage.png?alt=media&#x26;token=f322b79d-2799-405f-a659-8a5470e9946e" alt=""><figcaption></figcaption></figure>

### 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).

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FKBds0RWXS3oWyXRJGiP0%2Fimage.png?alt=media&#x26;token=dd55acfa-bc2b-400c-9e9b-5acc56a13f22" alt=""><figcaption></figcaption></figure>

### 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.&#x20;

### 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](https://docs.unity3d.com/ScriptReference/Vector3.html).&#x20;

## Start Position / Rotation

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2F7qDbX6oSBRl20lnvEcp0%2Fimage.png?alt=media&#x26;token=85ce47ed-5a30-4208-a5b2-eaf36e2ceb96" alt=""><figcaption></figcaption></figure>

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.&#x20;

<img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FKf5xoEgJHi6DpxUlFOQU%2Fimage.png?alt=media&#x26;token=43c8ec73-5479-46af-ac24-b211e4857707" alt="" data-size="original">

{% hint style="success" %}
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.&#x20;
{% endhint %}

#### None

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

{% hint style="info" %}
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.
{% endhint %}

#### 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.&#x20;

#### Set

Manually enter a specific position in local coordinates.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FigD3jP3iIVeL6hr1ZJZV%2Fimage.png?alt=media&#x26;token=1e5142f1-2f76-45f0-bc02-dab14ef58321" alt=""><figcaption></figcaption></figure>

#### On Target

Use this mode to place the object on the target being followed.&#x20;

{% hint style="success" %}
This mode is useful when using [Direct ](#direct)placement or anytime you want the following object to start at the same position as the target.
{% endhint %}

## 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.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FXAv1uL78sPNmviaX0TvU%2Fimage.png?alt=media&#x26;token=641fae5f-aa14-470b-9ca1-89f2cc789cc1" alt=""><figcaption><p>Close Gap and Overall Blend may be animated as well to transition Follow behavior over time.</p></figcaption></figure>

{% hint style="success" %}
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.&#x20;
{% endhint %}

## Overall Blend

This is the final blend slider which controls the overall influence Follow has on the object.&#x20;

{% hint style="success" %}
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.
{% endhint %}

## Additional Notes

{% hint style="info" %}

### 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](#limit-velocity) and the object's physical properties may need to be modified to get workable results.
{% endhint %}

{% hint style="danger" %}

### No Channel Link Time Offset

While it is possible to use [Channel Link](https://axongenesis.gitbook.io/timeflow/user-guide/timeflow-view/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.  &#x20;
{% endhint %}
