biyaniM / ALICE-IN-WONDERLAND-professional-nappers

Single Player, 3D Platformer movement-based game with Color and Level Mechanics with WebGL Builds
6 stars 1 forks source link

Transparent walls when player is not in camera FOV #68

Closed biyaniM closed 2 years ago

biyaniM commented 2 years ago

Implemented Fading of walls if the wall is in between the camera and the player, i.e., when the player is not visible in camera FOV. Important Note: This feature works only if the walls or the "to-be faded" game objects have a material made with Standard Shaders, i.e., not the Probuilder shaders and URP. Transparent Walls implementation

Change Description -

  1. Added a new layer "Fade" which needs to be attached to all the game objects we would like to fade in case they are in between the camera and the player. The fade layer helps identify the obstacles and also helps in isolating the fading so that it doesn't affect other game objects.
  2. Two new scripts added. One is attached to the main camera to maintain the camera's relative position to the player. Another script is attached to the walls which has to be faded. This keeps the track of all the objects in between the player and the camera. The list of these objects is filtered based on the layer and if they are of the type "FadedObject", i.e., the first script attached to the camera. Once the condition is met, the objects will be faded to a given alpha at a given speed. The alpha and fade speed can be changed based on the required effect. I have set the values to what feels correct according to me.

FUTURE NOTES: Need to add the "Fade" layer to all the walls on all levels and need to add new materials for the walls with the standard shader. This task should not be too much.