Light Detection Mechanic
Published: May 30, 2024
Last Edited: October 10, 2024
Tools used:

Light detection gameplay mechanic, done with Blueprint Scripting. Part of a side project I’m working on with some friends (@AntonioGil_Jogo and @1997Oldsmobile)
The core mechanic involves detecting whether an object is in light or shadow, and triggering gameplay changes based off that.
We originally used a simple singular sphere trace from the object centre, but that was inaccurate for non-sphere meshes, and occasionally gave unintuitive results. Additionally, you were bound to a binary on/off.
So I came up with a different solution. I generated a proxy mesh with Houdini, same silhouette, fewer vertices, and relatively even vertex density. I essentially treat this as a “light collision mesh” and cache the proxy vertex positions and vertex normals into the Actor.

Then on each update interval (which can be set per Actor), I compare all the vertex normals to the light direction with a dot product to see if the surface is even facing the light. Then, if that passes, I run a line trace to see if the vertex is lit or not.
This is more expensive than a single sphere trace of course, but gives much nicer results. It is more accurate, and can provide values between 0 and 1.
But it still runs fairly well, and could probably be optimized by transferring it from Blueprint to C++