[Solved] Non-colliding bodies having an effect on eachother

Topics: Developer Forum
Aug 7, 2012 at 7:31 AM
Edited Aug 7, 2012 at 7:35 AM

I'm trying to make a tile engine, but bodies that are not colliding with a sprite are still having an effect on it.

In this image there is a single sprite(the green box) with a ground detecting fixture and a single tile. The sprite rests right up against the tile like it should but the fixture attached to the sprite does not collide with the tile.


and in this one there are 2 tiles. The sprite is not colliding with the tile on the right, but when the tile is placed the sprite moves a few pixels upwards. Then when the tile is removed, the sprite falls back down and everything is fine again. Also, when the second tile is there, the fixture attached to the sprite does collide with the correct tile (the one on the left).


I have gone through the debugging, everything has the values I would expect, the debug view shows everything is fine and my OnCollision method is only being called by the tile that is actually colliding with the sprite.

The only thing I'm doing that might not be "normal" is reusing bodies for the tiles near the sprite and just moving their positions every frame (I'm 100% they're being moved to the correct locations). Could this be causing the problem somehow?

Aug 7, 2012 at 6:05 PM


A few ideas. First of all since we're talking about physics a "sprite" has no meaning. We have bodies that are like infinite planes and fixtures that represent geometrically defined collision primitives (via a shape) pinned in the body space so the bodies can collide through them. So first thing to check is if the visual sprite actually corresponds to the fixture's shape. You can scale them a lot to sort of "zoom" in to check that. Even 1px can make a difference.

Secondly a polygon has a small "skin" defined in Settings.cs. Default is 0.01m. This is what is actually used in collisions. If you're working at a very small scale where for example 1 cm is 1 px it will show. You can upscale a bit to make that insignificant or change the PolygonRadius in Settings. Definitely this is something that makes a tiling engine with physics difficult.

Finally moving bodies through unphysical means (aka teleporting by setting Position/SetTransform) can lead to ... unphysical behaviour. The engine would prefer if bodies were moved by forces or by setting velocities at least. It's the nature of the solver. Furthermore the issue is complicated by cached contacts, warmstarting and TOI so really many things can happen not all completely predictable. I don't think that's your problem but it could become if you prefer to move bodies by teleporting.

Hope this gives you some things to investigate.

Aug 7, 2012 at 11:55 PM

Making the PolygonRadius a bit smaller did seem to fix the body being pushed up for no reason thing, or at least make it visually unnoticable. But still can't seem to figure out why when there's a single tile, the body of the green box will collide correctly but the fixture attached under it won't.

Aug 12, 2012 at 6:54 AM

Solved the problem by upgrading to the newest version of Farseer. I was using whatever version the download link on the main page is to.