how I check collision with box2dlights in libgdx?

2019-09-05 01:47发布

问题:

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...

回答1:

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.