Sorry if this is not posted in the right location, I didnt really find anywhere else where this would be relevant.
I have been on a hell bent mission trying to create a simulated underwater in unity. Juggling between different shaders, and different tests and scripts. I have reached a problem that I am unsure how to solve (as my fix doesn’t appear to work properly).
When a player goes underwater it slows them down, changes the skybox and the colors all to match. Even so much as applies a gradient the deeper into the water you go. All is well:
When you come out of water, the script undoes everything that underwater did:
However, when you are half into the water, this happens:
My fix for this was simple move the camera down by a modifier so that when the player gets to a certain point in the water, we force the view under the water and when they exit the water or reach that same point again, we bump the camera back to its original position. The camera ends up freaking out assuming because it is in a OnTriggerStay() function (because we dont want them underwater as soon as they hit the water, only once the player is at the right depth). Is there a way to perhaps sustain the camera once we have moved it underwater? Below is the piece of code that moves the camera
private void OnTriggerStay(Collider other) {
if (other.gameObject.name == "PlayerObject") {
if (other.transform.position.y < transform.position.y - WaterLevelModifier) {
mCam.transform.localPosition = new Vector3(mCam.transform.position.x, mCam.transform.position.y-CameraModifier, mCam.transform.position.z);
}
}
}
Any help on figuring this out would be much appreciated.