Search code examples
libgdxcollision-detectionbox2dlights

how I check collision with box2dlights in libgdx?


It is possible to detect when a body is under light? ( Collision with the light and a body )

How I check this with libgdx?

Sorry for my english...


Solution

  • It could be easy to implements with raycasting :

    • With a point light, you have to perform a raycast from your body object to the light object, if the first returned body is the light then your object is under light.
    • With a directional (infinite) light you have to raycast from your object body toward light direction opposite, if raycast not returning bodies then your object is under light.
    • With Cone lights, it's the same as point lights but you also need to check angle with that light.

    Notes :

    • If your object body is big, you may perform multiple raycasts (from different positions).
    • If you have multiple lights, you need to perform multiple raycasts as well.