The Physics Gap

Some of the code I’ve copied from this forum has the same bug (at least for me!). One body falls onto another, but the two do not appear to touch. @mystaker’s code from Feb 16 drops a ball onto a rectangle, but the ball rebounds about a half-inch ABOVE the rectangle. @Ipda41001’s code from Jan 28 drops a small box onto a large one, but it lands a scant few pixels ABOVE the large box.

The programs themselves seem to believe the two bodies are touching. @mystaker’s ball does bounce! And @lpda41001’s box does indeed stop falling. On screen, though, there’s always this gap!

Is this a common problem? Something I’m missing or not understanding? I copied both codes as-is, but I’m more than willing to believe the problem lies with me! As always, thanks for any help.

In mine, it may be due to rounding and/or scale. if something is less than 1 pixel away it is in contact but drawing may round the pixel the other way. Since there are two objects it could be 2 pixels away.

When you zoom in with scale, the effect may get larger.

Another common cause is drawing something without using body.x and body.y. Especially when you draw at the bottom of the screen. The assumption is that the body is at the bottom and draw the lines without using the body.x and body.y which may not both be zero.

Then there is how the body is drawn. For a circle, the strokewidth() could be greater than zero but the stroke() is the same color as the background() which only leave the fill. For a rect(), is you use rect() you have to rectmode(CENTER) it but really it is safer to draw every edge as a line. Lines can also have stokewidth() issues.

Thanks @Ipda41001. I actually have tried messing with strokeWidth, but it didn’t solve the problem. So maybe it has to do with body.x and body.y, as you say. Am I correct in assuming that those are “anchor points” that mark the placement or position of the body?

If I understand correctly…

For a polygon if there isn’t a 0,0 and all the other values are positive it will still make .x .y 0,0.

For circles it’s in the middle.

Boy, this stuff is killing me! But I will keep trying. And thanks again for all the feedback.

My struggle is joints. I need to go back and try them sometime.

You are about one light-year ahead of me. I’m just trying to get a ball to bounce!