开发者

as3: Box2d how to find nearest bodies

How do I find bodies which are located near given body.

About the task. I am trying to detect b开发者_如何学JAVAodies which are near current. To do it, I've created quite a big collision shape, around the current body, and made it sensor. Collision event was triggered, but it's not what I need. Main thing is that collision event is called only first time when another body entered the detection field... And I want to be able to detect changes in bodies location, after it. (I am considering the fact that other bodies are moving inside detection field)


Why not just keep track of collision by storing the bodies in a collection? On a EndContact you can remove said body from the collection.

As for tracking the bodies inside this detection field, you could loop through this collection and check the positions.

Alternavily, if accuracy was not a huge concern, create a few sensor bodies, each with a smaller radius that the last and then you can detect which zone it is in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜