- Home /
When RayCastAll leavs an Object
Hi!
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!
Answer by eses · Aug 31, 2018 at 10:46 AM
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.
Thats wont work - because i dont have a specific wall - i have tons of objects in the scene - i dont want all of them have 'fading' methods.
@FakeBocha - What I said: "Use Tag, script or layers to decide what it is" - So this could just anything in your level, that is of particular layer / or has fader script.
I dont want to add to every object in my scene this script - it will hit the frame rate