top of page
Search

Making Occluding Objects Turn Transparent in a Third-Person Camera (Unity)

  • lappaschen0712
  • 9 hours ago
  • 2 min read

Updated: 22 minutes ago


Anyone who’s built a third-person camera knows the pain: sometimes, a wall or tree perfectly blocks your view of the player. It breaks immersion and makes movement feel clunky.

To fix that, I added an occlusion fading system — a simple yet elegant technique that makes any object between the camera and the player turn transparent automatically.

Situation when an object blocks the player and the camera
Situation when an object blocks the player and the camera

My Goal: Keep the Camera Natural, Not Cheating

I didn’t want to simply make the camera clip through walls or jump abruptly when something blocks the view. That would look unnatural and distracting.

Instead, I wanted a subtle, adaptive solution — one that respects level geometry but still prioritizes player visibility. Transparency felt like the most elegant answer: when something gets in the way, it should quietly fade away, revealing the player, then restore itself once the view is clear again.


Implementation Overview


So, I designed a system where the camera continuously checks for objects between itself and the player. Whenever something is detected, it temporarily swaps that object’s materials for a pre-defined transparent shader. When the object is no longer between the camera and the player, it restores its original materials instantly.

This happens seamlessly each frame, ensuring the player is always visible without breaking immersion.


How It Works


Each frame, the camera performs a SphereCast from its position toward the player’s head. If any objects are hit along that line, their Renderer components are temporarily replaced with a transparent material. Once the object no longer blocks the line of sight, it smoothly returns to its original material.


Detecting the objects between the player and the camera
Detecting the objects between the player and the camera
Add transparent material to the obstacles between player and camera and remove them if they are no longer blocking
Add transparent material to the obstacles between player and camera and remove them if they are no longer blocking

Now, you have a system which will turn obstacles' material into transparent.

Example from my TPS game
Example from my TPS game

Design Considerations


When building this system, I wanted to strike a balance between accuracy and performance.Using a SphereCast instead of a single Raycast allows me to detect a wider range of obstacles, even those with uneven geometry or small gaps. The radius ensures that thin poles, corners, or decorations that partially block the view are properly caught.

SphereCast
SphereCast

RayCast
RayCast

I also store the original materials of each renderer before applying the transparent ones. That way, when the camera moves and the obstacle is no longer blocking the player, I can cleanly revert the object to its normal look without any flickering or lost material data.


Another small but important choice: the system ignores any collider that belongs to the player or the player’s child objects. This prevents self-occlusion and keeps the character fully visible.



Closing Thoughts


This small addition completely changes how the third-person camera feels.The player always remains visible, environments stay readable, and the camera no longer feels like it’s fighting the level geometry.


It’s one of those subtle systems that most players never consciously notice, yet they feel its impact every moment they play.That’s the kind of design I love most: when engineering quietly makes the experience better.

 
 
 
bottom of page