Water Setup

The swim ability activates when it comes into contact with a water trigger. This trigger should be setup by performing the following:

  1. Create the GameObject that will contain the trigger collider.
  2. Set the GameObject layer to water
  3. Add a Box Collider to the GameObject, ensuring Is Trigger is set to true.

In the demo scene the water mesh is a child of the water trigger but this is not a requirement.

Custom Water Assets

The Swim ability is designed to be able to work with other water assets than what is included in the demo folder. By default the Swim ability will determine the height of the water by the top of the trigger’s bounding box, but this can also be set to a custom value. In order to set a custom value the SetWaterSurfacePosition method can be called on the Swim ability. This method takes a float which specifies the upper vertical position of the water plane. In the example below the position will be set to a value of 5.

using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.AddOns.Swimming;

public class MyObject : MonoBehaviour
    [Tooltip("The character that contains the swim ability.")]
    [SerializeField] protected GameObject m_Character;

    /// <summary>
    /// Sets the water surface position.
    /// </summary>
    private void Start()
        var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
        var swimAbility = characterLocomotion.GetAbility<Swim>();