how I check collision with box2dlights in libgdx?

落爺英雄遲暮 提交于 2019-12-11 22:01:55

问题


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.


来源:https://stackoverflow.com/questions/31910000/how-i-check-collision-with-box2dlights-in-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!