Prevent Camera From Looking Underwater

rsoult3

New member
Much like the Zelda games, I do not want the camera to look underwater.

I know the camera will not look through items in the SolidObjectLayers LayerMask. If I add the "Water" layer to SolidObjectLayers, then the camera will not look under the water. The problem is now the character can walk on water.

I want to add a new LayerMask NoCameraViewObjectLayers, which is basically SolidObjectLayers + Water (and any other layer I do not want the camera to go through).

This way, the character can still swim and walk in the water, but the camera will not look underwater.

How can I make the Camera Controller use my new NoCameraViewObjectLayers instead of the SolidObjectLayers when determining where it can look?
 
This will take modification to the view type. I would subclass the Third Person Adventure/Combat View Type and override the Move method to prevent the camera from going under water.
 
What would you suggest for doing that? I would like it to work just as it does for solid objects. The move function on the base class does not reference solid objects for it's SphereCast, just the invisible layers.
 
You will want to do it within the Move method - you can add another cast similar to the base class to adjust for water. Alternatively if you don't mind changing the source then you can adjust the base class cast directly.
 
Top