开发者

BOX2D Contact (isTouching) Problem

Here is my problem Image

BOX2D Contact (isTouching) Problem

I want to check开发者_JAVA技巧 if the balls are touching, which works perfect. Sometimes however that ball with the arrow isn't picked up which of course makes sense since it isn't touching anything. However, I want to give a little bit of leeway so that if a ball is say 4 pixels/0.001m away, it should be considered as touching. So what idea/ how would i go about implementing it. I looked at the isTouching code and here is what I can come up with.

     var b1 = body1;
var b2 = body2;

 Transform xf;
 Transform xf2;

  b1.GetTransform(out xf);
b2.GetTransform(out xf2);


var touching = AABB.TestOverlap(b1.GetFixtureList().GetShape(), b2.GetFixtureList().GetShape(), ref xf, ref xf2);

 if (!touching)
 continue;

I still need to test if there is a ball faraway, and I am clueless to what I can do.


Without knowing what all your classes are it's difficult to give an exact answer. But, the general principal would be to increase the bounds you're checking against. For example, if your shapes are circles of radius n, when checking collisions you could use a radius of n + 2. Note that you're still drawing the circle using a radius of n. You just use the increased radius for collision detection.

Similarly, with the AABB you'd need to increase the bounds by a couple of pixels. How you do that will depend on how your classes work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜