Light sensor - Get Light Intensity Value at Player Position?

I am working on a project in which I need to simulate a light sensor. As the user moves their player towards the light, the light sensor returns a higher value and as the player moves away from the light, the light sensor returns a lower value.

I have looked through the API docs and have not been able to find a way to measure the light intensity at a point in the map, is this possible with Playcanvas at the moment? Does anybody have a workaround? I am scratching my head at this one.

If you want to avoid to loop through all your lights and do some maths, maybe you want to check lightmapping. This would precalculate the light in all points of a surface, so (and I didn’t try) you could make a transparent surface at user’s level, lightmapping it, and get that texture.

1 Like

Okay so if I were to create a lightmap, which contains the light in all points of the surface, is there even a function I could use to get that value?

Where do those values live? I had a look through the documentation and I can’t seem to work it out.

My guess is that you will need to go deep in the source code, check PlayCanvas’ GitHub

It’s going to be hard, you may want to look for other simplier solutions like iterating all lights and doing maths.