When RayCastAll leavs an Object


I’m trying to make a raycast from my camera to my player and whe it hits an object i want it to fade, but when its no longer blocking the playr i want it to go back to normal!

thanks in advance!

Hi @FakeBocha

So you need a fading walls kind of script for 3rd person game?

Try something like this (crude pseudocode):

Raycast (or Raycast All) each frame towards player from camera.

If raycast hit a collider, check if it’s of type “YourWall” or whatever you make it be.

Use Tag, script or layers to decide what it is.

If wall is hit, tell wall to run it’s fader script. Make its state “fading” or something so it knows its already obstructing view, and is fading away. Do this for all walls that were hit.

if wall is not yet fading, start fading.

if in next frame(s) wall doesn’t get call from raycast script, it should start fading back to normal, no matter if it’s only partially faded at this point.