Walls blocking view of player

Anyone got tips or guidance on how I could make walls transparent or make an area around my player visible through walls I’ve tried casting a ray and having anything in-between the player and camera invisible but i couldn’t get it to work.

The easiest way, without using special shaders, is by doing exactly what you were trying to do, but I recommend using a sphere cast in this case instead of a ray cast because rays are just a line, this means that your character won’t be visible when the ray doesn’t touch the object between, this will happen a lot depending on the scale of your character.

The pseudo-code would be something like this:

  • Cast a sphere from the camera’s view towards the player. Preferably use this.
    • Using the list that the sphereCastAll returns:
      • Loop through all targets…
        • Grab the material and change the alpha value.

There’s an issue with this approach, How exactly are you going to make things visible again? Now that’s pretty annoying because there’s no easy solution for this.

Using that approach I would probably have another list that caches a reference of all the objects that were caught by the sphereCast and have a function that checks if those objects are still in between the character and the camera, if not, change their material alpha value to 1. The issue with this would be performance so you gotta be very clever as to when to run that method.

Perhaps you don’t even need to check if the objects are still in between, just see if the sphere cast list is empty, if it is return the objects’ materials alpha value to 1. But that would cause certain unexpected behavior like having certain objects not being visible until the list clears.

This idea was just something at the top of my head, you probably want to check some tutorials or come up with your own solution, something that is not as convoluted as this.

2 Likes

I didn’t think about sphere casts I will try to dig deeper into that I think ill just keep all walls that get in the way as ignoreraycast and finish the rest of these lessons before playing with that more but thank you :slight_smile:

1 Like

Privacy & Terms