Anyone set up the swimming pack with Stylized Water 2?

I know the swimming ability triggers when the character enters the box trigger works well on flat waters but looks bad with wave heights that are constantly changing like in a ocean. Any pointers on how to integrate and take into account the wave height and take into account of the wave height of the shader?


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>();
swimAbility.SetWaterSurfacePosition(5f);
}
 
Anyone who comes across this in the future this thread was pretty helpful and has a useful script that can be modified and used with Stylized Water 2. The approach is similar you set the third person controller swim ability water detector to custom then feed it wave height data from Stylized water shader to the line below.

swimAbility.SetWaterSurfacePosition(5f);

to get the wave height data see documentation here.

The wave height and normal can be read at any world position using this static function:

StylizedWater2.Buoyancy.SampleWaves(Vector3 position, Material waterMat, float waterLevel, float rollStrength, bool dynamicMaterial, out Vector3 normal);
 
Back
Top