Trace: Is face of charcater in line of sight (from any angle)

I want to check whether the player can see a certain part of a mesh - namly the face of a character.

My first naive idea was to just add a socket to the head bone and do a line trace from camera to that socket. But since the socket is inside the mesh I’d have to make the trace ignore the mesh. But than it would also be successful if the trace would go through the back of the head. If I move the socket outside of the mesh it only works for certain angles. So it seems to me I need a different approach.

How would you do this? Somehow I would need to map out a certain portion of the mesh and make the trace be successfull if there is an unobstructed line from my camera to any part of that face.

Hey @Gedinixan!

I’ve seen this method get used in a lot of AAA games for various reasons, as well as indies.

You can put the socket on the front of the character’s face- it doesn’t need to physically be attached, it could be 100m away if you wanted. As a socket is a point(it doesn’t have volume, it’s width, length, and height are effectively 0) it can go anywhere- Usually it would depend here how MUCH of the face you need to be visible.

If you need full face visible- one on each cheek, and one on forehead. Make sure to account for any bulging or etc, and attach it to the HEAD bone. Then, check for all 3 to return true.
You just need SOME of the face? Check for ANY of the three.

I think the issue here is trying to make it be a single trace when you would need to use multiple to get a more customizable use case! Traces are INCREDIBLY low impact, so go nuts.

Hope that helps! :slight_smile:

2 Likes

you can also use a Dot product to see if you hit the ‘front’ of the actor or you could put a material on the face only and return that material

1 Like

Thank you, I’ll try that

1 Like

Hey @Gedinixan! How did it go? Did you get it figured out? Let us know for future answer-seekers!