---
description: 🚧Under Construction
---

# Strafing

## Overview

**Strafing** is the act of moving sideways in a video game, either in relation to a target or the game's camera. Strafing allows a player to keep the camera focused on a target such as an enemy, while moving in a different direction.

{% hint style="warning" %}
Strafing requires new set of strafing animations on your Animator Controller. Make sure you have them set correctly
{% endhint %}

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

You can use Strafing for Locomotion, Fly, Swim, Swim underwater, and all the States that requires the animal to move.

## Requirements

### \[Can Strafe] Parameter

To activate strafing, enable **CanStrafe** on your Animal Component, on the **General** Tab.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FYkBWak2Ga7tLmdODXocP%2Fimage.png?alt=media&#x26;token=5f6e210e-4f8c-4d40-b06f-86177647258b" alt=""><figcaption></figcaption></figure>

### States \[Can Strafe]

The States also need the Strafe activation, since you can have strafing on the ground but not while Jumping or Swimming.&#x20;

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fr2QEiiogo7tvnT5IcQn3%2Fimage.png?alt=media&#x26;token=54281546-db01-4973-9fc8-cd02d5e39d8c" alt=""><figcaption></figcaption></figure>

### Strafe Animations

This will update the animator to change animations while strafing. If you do not have animations you can still use straffing with the default animations but it would look strange for grounded animations.

### Stances \[Can Strafe]

Also if you have the animations for the Stances you will need to activate it there too:

E.g. Steve can strafe while **Crouched** and on the **Default** Stance:

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FFLJTbzGrOycEShjlyyYF%2Fimage.png?alt=media&#x26;token=9fb83f84-480f-4f62-9737-b904db770974" alt=""><figcaption></figcaption></figure>

### Speed Modifiers

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FXeqFuA1lAiMHd1Un3pwX%2Fimage.png?alt=media&#x26;token=6c6f2d74-96dc-47f8-9b79-5f09718b6384" alt=""><figcaption></figcaption></figure>

For Inplace animations increase the Strafe Value on the speed modifiers to make the animal move in all eight directions. Change the **Strafe** and Strafe **\[L]erp** values to have the desired movement.

### Aim Component

Strafing Requires the [**Aim** ](utilities/aim)component. This will send the correct direction to Strafe to the Animal and the Animator.  Using the Camera Direction or a Direction to a Target

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F04QdVjVvoL612jkOcxWu%2Fimage.png?alt=media&#x26;token=71a7dd27-b335-4e5c-baf7-5ce8bc0f347b" alt=""><figcaption></figcaption></figure>

* Set the proper Animations on your Animator with the correct enter and exit transitions.

## Animator

### Parameters

All strafe animations for the Animal Controller requires 4 Animator Parameters.

_**Horizontal**_, _**Vertical**_, _**AimHorizontal (from the Aim Component)**_ and _**Strafe**_

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FybQR8nGJ4rZqHXctzy7b%2Fimage.png?alt=media&#x26;token=cf8dbd3f-c7e3-46f6-b30b-95e8cfa6f233" alt=""><figcaption></figcaption></figure>

These values will be updated by the Animal Controller and the Aim component and it will handle all  Strafing movement inside the Animator

### Movement

Here's what the Movement Strafing Blendtree for the State looks like.

![Blend Tree for Locomotion. Same applies to Fly, Swim](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MZ8eTB8oxDi8s0EC89e%2F-MZ9bpSNQHyXmONcPiJN%2Fimage.png?alt=media\&token=f2591161-d079-48c7-85ba-88fe3e66430e)

Each movement has 8 Direction Blendtrees animations:

These animations will be added with Horizontal and vertical Values of 1, properly distributed.

| Animation       | Vertical | Horizontal |
| --------------- | :------: | :--------: |
| Walk East       |     0    |      1     |
| Walk West       |     0    |     -1     |
| Walk North      |     1    |      0     |
| Walk South      |    -1    |      0     |
| Walk North East |     1    |      1     |
| Walk North West |     1    |     -1     |
| Walk South East |    -1    |      1     |
| Walk South West |    -1    |     -1     |

Inside each Direction Blendtree are the speeds for each direction the animal may have:

![1D Blend Tree for North and South Direction Using the \[Vertical\] parameter](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MZ8eTB8oxDi8s0EC89e%2F-MZ9e3l5JK7HYOEaemvH%2F1tZy0stsA6.gif?alt=media\&token=ee246651-fe7d-49b2-8b64-cc82d14f845a)

![1D Blend Tree for East and West direction Using the \[Horizontal\] parameter](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MZ8eTB8oxDi8s0EC89e%2F-MZ9fV4_y6-gn_oW4sI-%2FWRBhyNCzZi.gif?alt=media\&token=1d430998-1f0a-419d-be2a-59bdbfef258c)

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FWmdJPYIku6JFXdEjDkNp%2FUnity_dFYs1ZGnVm.gif?alt=media&#x26;token=afadf10f-7ab2-4e79-8855-09f8777c88a1" alt=""><figcaption><p>2D Blend Tree for Diagonal direction Using the [Vertical] and [Horizontal] parameter</p></figcaption></figure>

Diagonal Directions has a 2D Freeform Cartesian BlendTree.&#x20;

{% hint style="info" %}
Check Steve (Human) Animator for more details.
{% endhint %}



For the **Idle BlendTree,** we use the **AimHorizontal** (former **StrafeAngle**) Parameter. to rotate toward the Target in place:



![1D Blend Tree for East  Direction Using the \[AimHorizontal\] parameter](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MZ8eTB8oxDi8s0EC89e%2F-MZ9guJFtPXUSzZod7Ny%2Fj2ehaYJwWn.gif?alt=media\&token=a4714f34-95f4-4fe5-a8fd-1b3674ae5b07)

### Enter Transitions

For each **state** that has _Strafing_, Add an \[Enter transition] for each default animations.

E.g. For Idle. the Transitions conditions to the Idle Strafe should be **Strafe = true;** and it should be the first transition to check:

![Set the Transition for Strafe on top of the Transition List. So is checked first.](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M_lLeQRjSfLNx4IUhJw%2F-M_lVjQiMx74Ici0QBt7%2Fimage.png?alt=media\&token=4cc69bb8-5d1b-44b7-94aa-475244f58063)

That way it will always check first if the animal is strafing. If not then it will do the default Idle Animations

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fihdn1FFnNNgXitwFvt76%2Fimage.png?alt=media&#x26;token=277f2a24-22fe-41c0-8ff0-218b338983d7" alt=""><figcaption><p>The condition for the transition is [Strafe = true]</p></figcaption></figure>

Do the same for all the States where Strafing is enabled.
