# MPath

## Overview

MPath Component is the bridge between the Path Constrain and any Path/Spline solution you may use. It will take the values needed from a spline and it will translate them to constraint the character so it follows and stays on the path.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FwUZVjH5U4Z74SuLw6EWd%2Fimage.png?alt=media&#x26;token=9f429257-946f-4edb-9e26-7d075f4a0464" alt=""><figcaption></figcaption></figure>

## How it works

The MPath will use any type of IPath component to get the spline/path values. If an animal using a Path Constraint component enters the Colliders Bound of this component then the search for the closest point on the spline will start. if both search radius (MPath and Path Constraint ) are near, and Automatic is set to true then the character will be constrained to the Path.

{% embed url="https://streamable.com/imawmh" %}

## Requirements

* Any type of collider set as a trigger. (Box Collider Recommended)
* Any type of IPath Component **(**[**Path Link (Straight)**](path-link-straight)**,** [**Path Link Cinemachine**](path-link-cinemachine-path)**,**[ **Path Creator**](path-creator-sebastian-lague)**)**

## Parameters

### Path

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fky73T8dyoZSez9ynfVPB%2Fimage.png?alt=media&#x26;token=609e36b7-c41d-4c73-b3a8-d44104ab4030" alt=""><figcaption></figcaption></figure>

#### IPath

Type of Path solution to use, you can use any of the 3 solutions included **(**[**Path Link (Straight)**](path-link-straight)**,** [**Path Link Cinemachine**](path-link-cinemachine-path)**,**[ **Path Creator**](path-creator-sebastian-lague)**)**&#x20;

Add your solution to the path and then hit the refresh button.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fle1tj1AAqhgKHtp4JjYV%2FUnity_sB4KpA0chf.gif?alt=media&#x26;token=8ddffbf3-a653-4a51-a566-87a1d065627b" alt=""><figcaption></figcaption></figure>

#### Automatic

&#x20;The character will be constrained to the path as soon as both Search Radius instersect

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FkNMZZ5zkXli5Kj4PE0XG%2FUnity_2aWDEZWfQq.gif?alt=media&#x26;token=08a7f532-2faa-4dab-b453-2e16aaf26945" alt=""><figcaption></figcaption></figure>

Some paths are set to not be Automatic. To activate the, go to the Path Constraint component, add an Input connection, and use the method **`TryEnterExitPath().`**&#x54;his also works for exiting a path in the middle of it.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FPElTe7LUwBA2zkmfQlpF%2Fimage.png?alt=media&#x26;token=b6a83378-5384-4bf0-9e89-6aa043e8a7d8" alt=""><figcaption></figcaption></figure>

#### AutoChangePath

This allows to change automatically to a new path when the character is already in another path. The new path needs to be set to automatic also.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FBhtZsOZ5Xwp2Hq3gErn5%2FUnity_PXRT4Q7D2q.gif?alt=media&#x26;token=d7ecb595-b82c-4aa3-ac48-864d9395d8b3" alt=""><figcaption></figcaption></figure>

#### Lock Rotation

The character cannot rotate or change direction while on the path. (The character can walk backward)

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FQeFITowpyBbPUqAulcwE%2FUnity_Dsupu9MGGW.gif?alt=media&#x26;token=68aaffec-9ca2-47b5-a869-6d08a5e76132" alt=""><figcaption></figcaption></figure>

#### Follow Direction (Lock Rotation = True)

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FdAi6Qq9p2XbHu60ofHNB%2Fimage.png?alt=media&#x26;token=22dc4bbf-0931-4b0a-b5a3-381e1beaa283" alt=""><figcaption></figcaption></figure>

When lock rotation is true you can set the follow direction on the Path, this will automatically rotate the character to match the correct orientation during the path.&#x20;

* **None**: the Character will keep the starting path orientation when entering from the start or the end of the spline

|                                                                                                         Entering from End                                                                                                         |                                                                                                      Entering from Start                                                                                                      |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| ![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FoyopIvisdFrGZSa2hnte%2FUnity_HAGOGvOSth.gif?alt=media\&token=59bd7cdb-862d-404f-a06f-93d176ffd4ee)     | ![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F7o9wBPdvvQXpvtWNid6E%2FUnity_VHT9Yfs5mU.gif?alt=media\&token=f557d621-21c7-44a6-9d3e-260fc5bea69b) |

* **Forward**: The Character will be oriented to the Forward Path orientation  (Start to End)

|                                                                                                         Entering from End                                                                                                         |                                                                                                      Entering from Start                                                                                                      |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| ![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F9FSSQwhjgAI7vg0kJjlM%2FUnity_ULHBvYBPCs.gif?alt=media\&token=e2d306ab-0635-4c72-99d2-db21fbfb6829)     | ![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F7o9wBPdvvQXpvtWNid6E%2FUnity_VHT9Yfs5mU.gif?alt=media\&token=f557d621-21c7-44a6-9d3e-260fc5bea69b) |

* **Backward**: The Character will be oriented to the Backward Path orientation  (End to Start)

|                                                                                                         Entering from End                                                                                                         |                                                                                                      Entering from Start                                                                                                      |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| ![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FoyopIvisdFrGZSa2hnte%2FUnity_HAGOGvOSth.gif?alt=media\&token=59bd7cdb-862d-404f-a06f-93d176ffd4ee)     | ![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FVV1prepdkVU7DjK3fvaK%2FUnity_5bJExEfN9I.gif?alt=media\&token=c9c5cad5-3256-46c8-b581-39eb84687c06) |

#### Use Path Rotation

The Character will follow also the Path rotation values

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FwJVfwGYUmMBC0uzkf7sp%2FUnity_DuJIc90F0h.gif?alt=media&#x26;token=37ec8b75-dcf8-4238-939d-129d2ae9f756" alt=""><figcaption></figcaption></figure>

#### Alignment Offset

Applies an offset to the Character during the Path Constraint

#### Path Position

Use this Transform to have a gameobject follow the current position of the Character on the Path

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FXarMHmEnii6XLa0gxCYt%2Fimage.png?alt=media&#x26;token=716aa322-a733-4e4f-b2f7-efa9a3403dd5" alt=""><figcaption></figcaption></figure>

#### Can Exit on Start

The Character can exit automatically if it reaches the Start of the Spline

#### Can Exit on End

The Character can exit automatically if it reaches the Start of the Spline

#### Can Exit on Middle

The Character can exit automatically if a state interrupts the spline constraint. (E.g. Jumping on the middle of the spline)

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FHKahIP8QyfuKwyDiE5Mv%2Fimage.png?alt=media&#x26;token=e7f10f46-6113-4b8a-9621-d41df2e995cf" alt=""><figcaption></figcaption></figure>

#### &#x20;Interval

When the character is inside the Path bounds then a search will start to find if the character can be constrained when the search radius intersects. The interval is the time to execute this search. increase this value to increase performance. Reduce it to increase precision.

|                                                                                                          Interval  = 0.5f                                                                                                         |                                                                                                         Interval  =0f                                                                                                         |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| ![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FytuuvZcgNTM97in0yErj%2FUnity_AtDLKiMnyI.gif?alt=media\&token=4d22ae47-6707-4743-b304-80ba9996a8f8)     | ![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FWQEuE1J3ugaiQYvd2Nz0%2FUnity_rk0u0dR4V0.gif?alt=media\&token=91eabdcc-fb76-4b33-a6f5-719885c8833f) |

#### Path Cooldown

Once the character activates the path constraint, this time will need to elapse in order to exit the path again. This is useful to avoid entering and exiting the path in the same frame.

#### Search Radius

Radius to search a nearby Path Constraint component. When the Path Constraint sphere trigger and the Path sphere triggers intersect. It means the Character can activate a path.

#### Search Offset

An offset of the Radius value relative to the Path position.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FXLxNnUG48uiulMd18Lto%2FUnity_5hnQeZi8Gi.gif?alt=media&#x26;token=46a581a4-4c27-4831-ba72-3e2a5b8b3204" alt=""><figcaption></figcaption></figure>

#### Path Bounds

Collider assigned to the Path. This allows us to calculate searching for a character only when a character is inside the trigger.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F51K0rHw9mOnUiZRIkNiV%2Fimage.png?alt=media&#x26;token=bc856b88-2c4a-43a8-9992-8e86cdb5e58f" alt=""><figcaption><p>Box collider to limit the path bounds</p></figcaption></figure>

#### Layer

Filter what Layer can be used on the Paths  (Animal Layer is the Default).

### Animal

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FsDqSsJNtlYn624rngJcS%2Fimage.png?alt=media&#x26;token=f95cc29d-9372-40b6-ba9b-5864d8bb18b5" alt=""><figcaption></figcaption></figure>

#### Activate State

What state to activate when entering the path

#### Ignore Vertical

When is active the Animal cannot move on the Y-Axis while is on the path.  Disable this if you want to Jump while on the path.

(img)

#### Ignore Grounded

Ignore grounded can be used when there is no terrain or ground beneath the path..

(img)

#### Disable States

Disable States on the Character while is on the path. E.g. while on the path you can disable the Jump State.

(img)

#### Ignore States

States that will force an early exit on the path. E.g. Jump can force exiting the path if the Jump State is on this list.

(img)

#### Exit Any Mode

If enable, playing any mode will exit the path

#### Ignore Modes

Modes that will force an early exit on the path. E.g. Damage can force exiting the path if the Damage Mode is on this list.

(img)

### Reactions

...

### Events

...





