🐟Swim
1.4.2c
Last updated
1.4.2c
Last updated
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.
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.
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.
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
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
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:
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
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:
The Swim need a new Speed Set that affect the Swim State
Layer used to search which gameobject is set as water.
Lerp value for the animal to stay aligned to the water level. Higher values will align to the surface faster. (Img)
When entering the water, the Animal will sink for a while. Higher values will return to the surface faster.(Img)
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.
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.
Gives an extra impulse when entering the state using the accumulated inertia from the last State.
(Img)
Spherecast radius to find water using the Water Pivot Position.
(Img)