Aug
27
2021

Boat Attack URP Water: Add Underwater surface flip

Just modify 2 lines from the scripts and you get visible waterplane when going below surface. The idea is to check camera Y position, if below 0, flip normal and flip matrix for mesh.

Boat Attack Project:
https://github.com/Unity-Technologies/BoatAttack

Inside Water.cs & PlanarReflections.cs replace these 2 lines:

// find line
Vector3 normal = Vector3.up;
// replace with
Vector3 normal = realCamera.transform.position.y < 0 ? -Vector3.up : Vector3.up;
// find line
var matrix = Matrix4x4.TRS(newPos + transform.position, Quaternion.identity, transform.localScale); // transform.localToWorldMatrix;
// replace with
var matrix = Matrix4x4.TRS(newPos + transform.position, Quaternion.Euler(0, 0, cam.transform.position.y < 0 ? 180 : 0), transform.localScale);
view raw Water.cs hosted with ❤ by GitHub
urp underwater surface flip

4 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.