# Ledge Grab

## Overview

The Grab Ledge State is used to perform a quick ledge climb when the character is near a flat surface.  Its State [**ID** ](https://malbersanimations.gitbook.io/animal-controller/scriptable-architecture/scriptables/scriptable-ids#states-ids)is **8.**&#x20;

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F5xFITNrQr6v6NMIJssiF%2FUnity_CeFxzctzGO.gif?alt=media&#x26;token=76a662a8-76e0-4825-b17e-8e15b78dcfa4" alt=""><figcaption><p>Climbing Edge with differnt profiles</p></figcaption></figure>

## Creating the State

To create a new **Ledge Grab** State, click the \[ + ] button on the States list.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FPeS1bJkMQYOMKRX0FiVN%2Fimage.png?alt=media&#x26;token=38f7032c-30cd-4f1e-8560-b720da0aeb2a" alt=""><figcaption></figcaption></figure>

Or just duplicate any of the already created **Ledge Grab** States Assets of any animal you own and drag it to the States List.

## Priority

The state should have a higher priority than [**Idle**](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/idle), [**Locomotion,** ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/locomotion)and [**Fall**](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/fall). but below [**Death**](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/death)**,** since the animal can be killed at any time. Remember States work by priority; If you need to Jump or Fly while the animal is in the **Ledge Grab** state, those states should have a higher priority.

## Requirements

* The state uses raycasting to find nearby surfaces. These colliders need to have the same Layer as the Ledge Layer Parameter

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FRrSZDoKJYEKJioXFevw1%2FUnity_w0dIKBBB1w.gif?alt=media&#x26;token=990a61d5-9489-4186-b178-984f17d4c0cc" alt=""><figcaption></figcaption></figure>

## Activation

The state uses the values from the Profiles to cast rays that can detect colliders in front of the character. 3 Rays are Used for each Profile.&#x20;

* A first ray on the Top (Green) is cast to check if there's no Collider in Front.&#x20;
* A second ray is cast starting from the end of the first ray to find a collider downwards (Red)
* A third ray is cast from the chest of the character, to detect a wall in front of the character (Yellow)

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FiA56AEYyROExlnq15DKe%2Fimage.png?alt=media&#x26;token=15e00683-fad2-437b-8d72-2d136768b57a" alt=""><figcaption></figcaption></figure>

The State will be activated if the **Top** (**Green**) does not detect a collider and the **Down (Red)** and **Wall(Yellow)** rays detect a collider.

### By Input

If the rays detect any of these colliders, use the Ledge State Input value to try to activate the state.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F61m1Xk4hV7zpOczpiVM9%2Fimage.png?alt=media&#x26;token=4ddcc57b-5eb9-488b-8f10-05606ce2e20b" alt=""><figcaption></figcaption></figure>

### Automatic

Set the Automatic Parameter to true and the Animal will activate the State as soon the Ray finds any collider that can be ledge climbed, and the conditions of the rays are met.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FsUoGylOdbip3d7jhGNiS%2Fimage.png?alt=media&#x26;token=5b481d43-b287-4dc9-b365-a3f390d1e9fc" alt=""><figcaption></figcaption></figure>

### Zones

&#x20;Zones can also be used to activate the state. Set a zone in front of a climbable surface and the State will be activated.

### Reactions

Animal Reactions can be used to activate the state. Check [**Reactions**](https://malbersanimations.gitbook.io/animal-controller/main-components/reactions)

## Exit Conditions

Internally, the exit conditions will be executed to check if the State can exit.

In the case of Ledge Climb the State will exit automatically when the Exit Time of the Active profile has elapsed.

## Animator

Ledge Grab Substate Machine

The Climb state requires an Animation State that is in charge of the Ledge Grab movement.&#x20;

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FLAK4kJz6BiFXin8CrBdN%2Fimage.png?alt=media&#x26;token=f379c466-da03-4db5-af38-5bb661e13932" alt=""><figcaption><p>The Transition Enter Condition of this state is State=8</p></figcaption></figure>

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FvfqYjdb7VeksfD9II589%2Fimage.png?alt=media&#x26;token=a487e6ef-4763-4350-baaf-10db667452ae" alt=""><figcaption></figcaption></figure>

### Transition Duration

The positioning and alignment of the character to the correct position is determined by the transition time of the Any State to the State Animations. By default is set to 0.1

{% hint style="danger" %}
This value is really important and is used in the Profile Offset Position values.
{% endhint %}

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FFFX517YeHW7slZursHkv%2Fimage.png?alt=media&#x26;token=8bd39f67-bae0-4f32-9744-10a8246412fa" alt=""><figcaption></figcaption></figure>

### Core Animation

All States have a core animation on which the Animal will stay while the state is active. In the case of Ledge Grab will be the animations for each ledge Grab Profile.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FOJvHFk6kCbbCTL4KzaSF%2Fimage.png?alt=media&#x26;token=20d4227a-8784-40da-bdc1-cda10f543dc8" alt=""><figcaption></figcaption></figure>

The condition to enter the right profile is the value of the Enter Status Parameter.&#x20;

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FQ9pPPof39nGsGdCAiz2b%2Fimage.png?alt=media&#x26;token=033e6080-ec6e-42df-97f0-0aafab8dc773" alt=""><figcaption><p>Value of the State Enters Status Parameter on the Animator</p></figcaption></figure>

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FS6zJClpagdgYBwtTSSXF%2Fimage.png?alt=media&#x26;token=e06b8b87-a77f-40c5-84a0-edf48e1e6fb3" alt=""><figcaption><p>Value of the Enter Status on the ProfileState</p></figcaption></figure>

This core animation must be always **tagged** just like the Name of the State ID. &#x20;

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FiPUVJi5QEEF4v7Nb6D6I%2Fimage.png?alt=media&#x26;token=a6654a3f-becf-4124-a01d-975a235e344e" alt=""><figcaption></figcaption></figure>

## General \[Tab]

The basic setting for the Ledge state is very similar for all the animals.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FP8S8gR82YQgPEhJ5DVOs%2Fimage.png?alt=media&#x26;token=7db740ce-727c-4e78-b364-e67bc7b75c8d" alt=""><figcaption></figcaption></figure>

## Tags\[Tab]

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F1i0LY8L4HkHc9vp1BPiG%2Fimage.png?alt=media&#x26;token=54c8fbe4-0e8c-46c8-a12e-36695c25108e" alt=""><figcaption></figcaption></figure>

Since the state only uses an animation per activation, meaning there are no enter or exit animation clips, there is no need to use Tag modifiers or Enter/Exit Tag.

RootMotion, +Rot , +Pos, and Ignore Lower State should be enabled, all other tag modifiers should be disabled.

In this state the animal is not Grounded, Gravity is disabled, and there is no Orientation to the ground.

## Limits \[Tab]

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F4asuK0X4qTYHOFq6LK2C%2Fimage.png?alt=media&#x26;token=e9260237-3f5f-4b05-8684-98edad113d82" alt=""><figcaption></figcaption></figure>

Limits can be set to your own needs. If you want to disable/sleep the state while the character is in another state, or when is playing a mode, or stance; it can be done in this section.

E.g. Ledge grab is sleep if the character is on swimming underwater.

## Speeds \[Tab]

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FGZCBTjCHi3p1qC2uHvbV%2Fimage.png?alt=media&#x26;token=bab44b8b-049c-41f7-bb1e-cbec5b1514ad" alt=""><figcaption></figcaption></figure>

This state does not require any Speed Modifiers. All the movement is done either by RootMotion or via the [Profiles](#profiles).

## Ledge Parameters

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FMri8jGtBRvoghmvNHBdv%2FUnity_2KLWhXZPq6.png?alt=media&#x26;token=db7ac99f-a21a-420a-b0d2-4daddbec8560" alt=""><figcaption></figcaption></figure>

### Ledge Layer

Layer to Identify Edge surfaces

### Automatic

The state will be activated as soon as the Try Activate conditions are met (Rays Conditions) No need to use the Input

### Kinematic

The character rigidbody will be kinematic as long as the state is active. Use this when collides are not allowing the correct movement of the State)

### Wall Distance

The distance needed to place the character in front of the wall when the state is activated

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FbFfETgOZ9o5KGo0qMRhQ%2FUnity_RPh66Ofhz2.gif?alt=media&#x26;token=bcc7a726-0432-4a9d-a1c3-987d197e3a04" alt=""><figcaption></figcaption></figure>

### Min Terrain Angle

If the Top Surface is not Flat. It must have in the range of 0 and this value in order to be able to activate the State

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F5DOaxfEzF6yUxCaDfF5n%2Fimage.png?alt=media&#x26;token=83bd1a87-e0f0-489f-97c7-ff4c660e2fab" alt=""><figcaption><p>angle 35 wont activate the state if the value of Min Terrain is lower than 35</p></figcaption></figure>

### Forward Length

Global Front Distance to check colliders in front of the character (Green and Yellow Ray Length )

### Wall Checker

Vertical Distance to check the Wall in front of the character (Yellow Ray Height)

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FQIwLLIlpWteyBIR4jTLE%2FUnity_kjjViloMC0.gif?alt=media&#x26;token=468b1f09-b167-492d-b9c4-8254839accf3" alt=""><figcaption></figcaption></figure>

## Profiles

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FzAg4yaWyxawQb5sae1i5%2Fimage.png?alt=media&#x26;token=df4a44f9-18e6-493d-a9a0-1f0a8d300160" alt=""><figcaption></figcaption></figure>

### Name

Name of the Profile&#x20;

### Enter Status

This value is used by the Animator to activate the correct animation

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F5xFITNrQr6v6NMIJssiF%2FUnity_CeFxzctzGO.gif?alt=media&#x26;token=76a662a8-76e0-4825-b17e-8e15b78dcfa4" alt=""><figcaption><p> "Ledge Grab" has a Enter Status of 0 and "Step Up 1 Meter" has Enter Status of 1</p></figcaption></figure>

### Max V Speed

Maximum Speed the character may need to check and use a profile.

&#x20;E.g. If the Animal is Walking (Speed 1) or running (Speed 3), you can have different profiles for each activation.

### Forward Multiplier

Local Forward Length applied to the global Forward Length **(Green Ray)**

### Height

Height value for the Top Ray **(Green ray).**

### Ledge Exit Distance

Height Value of the Down Ray. This ray is in charge of finding a flat surface (Red Ray)

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F7rnalX6HM59KwH4H5HMq%2FUnity_jsUPVQQz4C.gif?alt=media&#x26;token=2ed17539-7dd4-4de3-8c25-f88c04fe785c" alt=""><figcaption></figcaption></figure>

### Exit Time

The time needed to activate the **Allow Exit()** Method on the state. (by Default is 0.9 almost at the end of the animation). This allow other lower priorities states to activate themselves

### Align Offset&#x20;

Offset values on the Vertical and Forward position applied to the character when it starts the state.

Try different values until you get the proper hand placement on the state.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FpPmvwq0WDzDqHPENcheV%2FUnity_oesD78DNiD.gif?alt=media&#x26;token=f8ca7279-84e7-4b42-880c-25af85cc8dbe" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
This Align value is very tight to the Animator Transition Time. If you change the transition time you need to update these values.
{% endhint %}

### Orient

When enabled, it will orient the character perpendicular to the wall.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FRedF9wnVCwGp3TewMyEs%2FUnity_YtlOT18Hen.gif?alt=media&#x26;token=0df41065-5a0c-4595-be0d-8b415811b4b4" alt=""><figcaption></figcaption></figure>

### Orient Smoothness

If Orient is enabled, this is the smoothness value to orient the character perpendicular to the wall.

### Additive Position

When is enabled, it will add vertical and forward movement to your character in case your animations are not RootMotion.&#x20;

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FGfajiLR597M8neo1oY0R%2Fimage.png?alt=media&#x26;token=6228531a-8afb-4e60-b435-e2182e83fba4" alt=""><figcaption></figcaption></figure>

### Height Speed

Amount of Vertical Push added to the character when the state is enabled

### Forward Speed

Amount of Forward Push added to the character when the state is enabled

### Height Curve

The multiplier of the Height Speed throughout the whole animation.

&#x20;E.g. in the First half of the animation, the character will be pushed in the vertical axis, but in the other half, NO Vertical movement will be applied.

### Forward Curve

The multiplier of the Forward Speed throughout the whole animation.&#x20;

E.g. in the First half of the animation, the character will NOT be pushed in the Forward axis, but in the other half will be moved forward.
