Shape overlap checking without "physical" Collision

Hi Box2d friends,

maybe there is an easy solution to the following problem: I want to check bodies in my world for if they overlap, but i don't want them to collide, i.e. i want two balls to continue flying as they were, but i wnat to see if their shapes overlap.

I figured ot that that collisions between different objects can be turned on and off selectively using maskBits and categoryBits, but as Ive seen it, if they are not set up for collision, there is no overlap checking as well (which normally does make sense as regards performance). But I have certain Areas in my JumpNRun game (water for example) that i would like to see if the player is in.

Right now i am using a rather awkward way of using the b2Collision class directly and calling the appropriate checking function for each pair of shapes (checking all shapes of all bodies with all shapes of all bodies 🙂). This technique becomes rather slow if there are a lot of areas to be checked and I noticed that box2ds normal collision detection is A LOT faster.

So I guess I am doing something wrong...


Andi
Ok, I found out that I need sensors... but they aren't there yet in the AS3 Port, right?

😮 seems I am talkin gto myself...
Yeah sensors haven't been officially added to the AS3 port, but they are very easy to add in. See
this post. I linked to the juicy part of the post with the code. Erin's post is probably what you want, but it's in C++. Not hard to translate though, but you'll also have to add a couple variables as is mentioned earlier in the post. It really only amounts to ~10 lines or so (the part you have to add in).

Ok I went ahead and pasted in the AS3 version, but you have to add the variables mentioned by NintendoBen.

Code:
      if (cn.contact.m_flags & b2Contact.e_islandFlag)
      {
         continue;
      }

//------------->this is the beginning of what you add in               
      if (cn.contact.m_shape1.m_sensor == true || cn.contact.m_shape2.m_sensor == true)
      {
         continue;
      }

      if (cn.contact.GetManifoldCount() == 0)
      {
         continue;
      }
//------------->end of added code

      island.AddContact(cn.contact);
      cn.contact.m_flags |= b2Contact.e_islandFlag;


I've been using this for quite a while and haven't run into any problems 😀
Ok, brainclog, thank you very much, sir. I pasted it but didnt test it yet. That comes now. I'll keep you informed how it worked...
😮







it works!

perfectly!

so good!

fantastically well!

thanks brainclog & all the others! Box2d is great software and has great supporters!

No we can all start building pinball machines 🙂
That's great that you got sensors working, I consider them an essential feature. 😀 Consider yourself on my "Premium Box2D/AS3 Tech Support" list if you need anything else 😉 (for helping with my GC problem)

Original thread: https://box2d.org/forum/viewtopic.php?t=511