Line Trace from Camera to Detect Closest Object

Hello!

I’m terribly new to UE4 and my teammate and I are making a balance game where you create structures and avoid obstacles to reach a certain height.
Right now, we want to make it such that the obstacles closest to camera become translucent so that we can see the structure through them. I’ve made a separate class for all obstacles with a static mesh and collider, and I’ve been trying to use Line Trace to detect which one is closest so we can change material, but I’m not being able to get this to work.

Does anyone know how I could pull this off ><

You can set the translucency in the materials themselves:

It’s a simplified version, you can tweak it further to make more gradual translucency and what not. 200 is the distance between the camera and the object, you’ll need to adjust is depending on your setup, 1 and 0.4 are opacity values, where 1 is fully opaque, 0.4 is semi transparent.

314127-translucency.gif

Thank you so much for this! It’s working very well but we’ll have make all our materials translucent for this to work in a ‘plug and play’ model (which is our brief at the moment), we’re trying to see if we can create a similar translucent material and switch to it based on distance from camera.

Appreciate such a thorough and prompt response!

hey there!
i think you can handle this with collision.
put a sphere collision on your camera, make a custom collision channel so its overlap only your object needed (for exemple call it thinwall, turn your sphere collision to only overlap thinwall, and set your objects type to finwall.
then use the on actor begin overlap / get overlaping actors, find the closest to your camera and change it, and leave the others.