Collision Margins confusion.

Post Reply
Wil McV
Posts: 18
Joined: Tue Aug 26, 2014 5:46 am

Collision Margins confusion.

Post by Wil McV »

Hello all,

So I stumbled across this forum post

http://www.bulletphysics.org/Bullet/php ... 995#p31234

from a while ago about collision margins and shapes. I watched the video and thought to myself, this is amazing. It's going to solve all of my problems. However when something looks to good to be true it usually is, so low and behold when I implemented functionality to change the collision margin into my program, it didn't produce the results I was expecting.

The video in the thread makes the collision margins out to be a kind of padding around the collision shape and states that the collisions can be resolved better when shapes are penetrating each others margins rather than their actual shapes.

When I looked at the code in a few cases the margin is subtracted from the original shape rather than added as a form of padding so if someone made the margin big enough the implicit shape dimensions could end up being negative on all axes which would cause problems wouldn't it? Is it a case that if I want it to act as some form of padding that I need to scale the shape to be the size I would expect including padding then use the margin to kind of shrink the shape back to the original size?

Would someone be able to explain what the margins do and how they work? or point me in the direction of another post which does this?

Thanks in advance.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Collision Margins confusion.

Post by drleviathan »

It doesn't make sense to use a margin larger than the smallest thickness of the shape. I'm guessing that the code doesn't check for that case and therefore puts the onus on the game developer/designer to do the right thing, else risk undefined behavior.

As I understand it, when you make a btBoxShape the margins will automatically be subtracted from the halfExtents, which is why the API for that class provides these methods:

Code: Select all

    btBoxShape::getHalfExtentsWithMargin()
    btBoxShape::getHalfExtentsWithoutMargin()
So if you were to make a 1x1x1 box (halfExtent = 0.5) then the true halfExtent of the box would be 0.5 - margin.

Similarly for other convex shapes.

Yes, if you want the object to appear to collide with a gap between it and other objects then you need to supply it with a bigger shape than its rendered size, whether you use more margin or not. Making the margin larger just smooths out the sharp edges of the shape while keeping the overall dimensions unchanged (for most cases... as I recall the video mentions a few exceptions).

One main point of the video was that if you want your objects to collide with rounded edges you can get that effect for free by using larger margins rather than supplying more points in your convex hull or more triangles in your mesh shape.
Post Reply