Subtractive (or negative) collision

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
Posts: 8
Joined: Sun Jun 25, 2017 9:05 pm

Subtractive (or negative) collision

Postby CrowbarBarian » Sun Jun 25, 2017 9:47 pm

Hi all,
Box2D is a nice physics engine, and seems to be just what I've been looking for.

But, before I go ahead and start working on my game, there is one feature that I would like to have which would make certain game-play situations a lot easier and faster to code. What I'm wanting is a sort of CSG for collision. I've read previous posts on this using CSG for deformable terrain and such, but those methods require the programmer to use a cumbersome and time consuming operation where the section of terrain is altered via the Clipper library, re-triangulated and then reintroduced into the world. This works, but I think there might be a simpler solution.

What I'm talking about is negative collision shapes in the form of circles and convex polygons, but are turned 'inside-out' for collision testing purposes.
Maybe a diagram would help:
subtractive collision diagram
Box2DSubtractiveCollision.png (11.28 KiB) Viewed 445 times

Objects labeled '1', '2', and '3' are ordinary dynamic bodies, the blue box is a static terrain object, and the green circle is a subtractive collision zone that is attached to the box. Now, what happens is, in theory, whenever a collision happens with the terrain, AND is within the subtractive object, it is disregarded. However, for example like with object 3, when an object touches the border of the subtractive object and the box the collision is handled as if object 3 was touching the box but with the touched surface being the inside curve of the circle.

Perhaps this isn't the best way to explain quite what I want, and there may be issues with the internals of Box2D that prevent such collision testing from working. But I think if such a system were to be implemented it could be a very powerful feature.

Really, what I want for my game is a smooth transition for ramps via a circle's curve instead of a subdivided polygons in the outline of a circle, which I think is memory and processor intensive. The fact that it could be used for making dynamic holes in terrain and other objects is just gravy.

So, is this idea feasible, or is it done better another way?

Return to “General Discussion”

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests