๐ŸŸSwim

1.4.2c

The Swim state is in charge of allowing the character to swim on water. Its State ID is 4.

In version 1.4.2c+ and above, the swim state can be used with mesh colliders.

In order to make it work you need to disable all water layer interaction in the Collision Matrix.

How it works

The swim state uses colliders to know when the animal is inside a Water trigger with the Layer "Water".

A sphere cast is called in a given interval to find if the character is inside that trigger. If that condition is met then the State will be activated.

Creating the Swim State

To create a new Swim State Click the Plus button on the States list:

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

Priority

The state should have a higher priority than Idle, Locomotion and Fall.

If you want your Character to jump while in the water: Jump should be above Swim on the State list

Common State Properties

The basic setting for the Water states are very similar for all the animals

  • ID = Swim State ID

  • Input: None (This State is activated automatically when entering a source of water)

  • General

    • RootMotion = True

    • Sprint = true

    • Gravity = false

    • Grounded = false

    • Custom Rotation = true

    • Orient to Ground = false

    • Ignore Lower States = true

    • Persistent = false

    • Lock Movement = false

    • Lock Input = false

    • Additional Position Speed = true

  • Exit Frame = true

  • Sleep From State = 0

  • Sleep from Mode = 0

  • Queue From = 0

  • Tag Modifiers = 1

    • Swim Enter

Tag Modifiers

The Swim State has a โ€œSwim Enterโ€ Tag Modifier by default. This allows the swim state to have an entering animation before entering the swim animation and allows you to modify common parameters on the State while it is playing the Enter Water Animation.

If your character does not have the Enter Water Animation this can be ignored.

The values for the Animal parameters that the Swim Enter modify are:

Requirements

The state needs a pivot called Water in order to work. To create a new Pivot simply increase the pivot Array size

This pivot will be used as the position to find a water source, a Gameobject set in the Layer: Water.

The water pivot also acts like the water level position. if it is higher it will sink more the animal, if it is lower it will make it stay higher in the water.

Here's the difference between the Height (Y Position) of the Water pivot

Animator

The Swim state requires Animation States that are in charge of the Swim movement.

All states have a core animation state. For swim is a swim blend tree with the Tag Swim.

Since the Swim is a moving state the Speed Multiplier must be set as Parameter "SpeedMultiplier"

You can take a look to the Wolf Lite Animator (Swim State) as a guide to see how is set up:

Speed Set

The Swim need a new Speed Set that affect the Swim State

If your swim animations are NOT RootMotion then you need to increase the Position and Rotation values to be greater than zero

Swim Parameters

Water Layer

Layer used to search which gameobject is set as water.

Align Smooth

Lerp value for the animal to stay aligned to the water level. Higher values will align to the surface faster. (Img)

Bounce

When entering the water, the Animal will sink for a while. Higher values will return to the surface faster.(Img)

Try Exit Time

If the Animal Enters it will wait this time before trying to exit the water. This avoids unwanted entering/exiting the swim state in the same fotogram.

Water is Static

Means the Water does not change the shape. Enable this when your water is always an horizontal plane. This avoids unnecessary raycasting and increases performance.

Keep Inertia

Gives an extra impulse when entering the state using the accumulated inertia from the last State.

(Img)

Radius

Spherecast radius to find water using the Water Pivot Position.

(Img)

Last updated