Why does the top of my physics object shift after hitting the ground?

I have a simple application with some objects with a static body and another object with a dynamic body that falls down onto the static objects, These static objects are the ground.

Once the dynamic object hit’s the ground, the top half of it slightly shifts to the left.

Here’s two screenshots with physics.setDrawMode( “debug” ) on,

Before it hits the ground:

[SPOILER]

w0nU7n6.png

[/SPOILER]

After it hits the ground:

(Expand the image to see the small change)

[SPOILER]
pwsq2ic.png

[/SPOILER]

How do I fix this?

Or does this even matter?

It is rotating, not distorting. Stuff like this happens because Box2D is a real world simulation. Nothing lines up perfectly. It’s only a problem if you really need the dynamic object to stay level, in which case you could set .isFixedRotation=true

as per horacebury:  it’s rotating

are you absolutely positive that everything (box and all ground) are perfectly aligned and configured? (no overlap, no fractional coordinates, no excessive density differences, no strange bounce values, no crazy gravity scales, no manually applied impulses from elsewhere, etc)

(in my experience, box2d should easily handle this type of gravity-only-flat-drop simulation without unwanted rotational artifacts if set up perfectly)

box2d would appear to be (circumstantial evidence) solving the rightmost collision first, where the collision normal is enough off-center so the “repel out of collision” force applied would tend to impart the rotation you’re showing (which the second leftmost collision would halt)

or try adding a tiny bit of linear damping to your dynamic box - i’ve found that box2d can continue “inchworm”-like collide-resolve-repeat indefinately if there’s no damping, which might be at play here too??  (you could try some angular damping too, but sometimes the obvious is not the culprit - it may be that continued linear motion is what is leading to your rotation, and you’d want to “fix” the problem as early in the simulation as you can)

BTW… if your whole ground is static, then you’d be far better off just making it one large single body.  (you could still DRAW individual tiles, just don’t add them as individual bodies)

Thanks guys!

It is rotating, not distorting. Stuff like this happens because Box2D is a real world simulation. Nothing lines up perfectly. It’s only a problem if you really need the dynamic object to stay level, in which case you could set .isFixedRotation=true

as per horacebury:  it’s rotating

are you absolutely positive that everything (box and all ground) are perfectly aligned and configured? (no overlap, no fractional coordinates, no excessive density differences, no strange bounce values, no crazy gravity scales, no manually applied impulses from elsewhere, etc)

(in my experience, box2d should easily handle this type of gravity-only-flat-drop simulation without unwanted rotational artifacts if set up perfectly)

box2d would appear to be (circumstantial evidence) solving the rightmost collision first, where the collision normal is enough off-center so the “repel out of collision” force applied would tend to impart the rotation you’re showing (which the second leftmost collision would halt)

or try adding a tiny bit of linear damping to your dynamic box - i’ve found that box2d can continue “inchworm”-like collide-resolve-repeat indefinately if there’s no damping, which might be at play here too??  (you could try some angular damping too, but sometimes the obvious is not the culprit - it may be that continued linear motion is what is leading to your rotation, and you’d want to “fix” the problem as early in the simulation as you can)

BTW… if your whole ground is static, then you’d be far better off just making it one large single body.  (you could still DRAW individual tiles, just don’t add them as individual bodies)

Thanks guys!