I'm having a problem with the Farseer Physics Engine, where in a tiled environment, my object will at times interact with corners of others objects, even if they align perfectly.

Tiling Physics using Farseer

I've read about people suggesting that you calculate and create one larger object, using Marching Squares or something similar. This is not an option however, as I'd like each tile to have different physical qualities, like different friction and restitution.

My question is, what exactly is causing it, is it float precision issues or something else? And is there a way to fix it, without breaking the whole physics engine?

  • \$\begingroup\$ I wonder if you could simply expand the collision boxes by one pixel, so they overlap a bit. It may see the surface as more connected perhaps. \$\endgroup\$ – Doug.McFarlane Aug 25 '11 at 19:02
  • \$\begingroup\$ @Doug: I just tested that, and it didn't make any difference. \$\endgroup\$ – William Mariager Aug 25 '11 at 21:21
  • \$\begingroup\$ Are the ground tiles static bodies? \$\endgroup\$ – bummzack Aug 26 '11 at 6:19
  • \$\begingroup\$ @bummzack: Yes they are. \$\endgroup\$ – William Mariager Aug 26 '11 at 13:57
  • \$\begingroup\$ I am having the exact same issue. I get the "bouncing" effect when my movable object is a rectangle or a circle. I also cannot convert multiple squares into one large rectangle because I want the player to have the ability to "remove" individual tiles in certain situations. \$\endgroup\$ – user9534 Aug 28 '11 at 5:48

Farseer uses an iterative solver, so when your wheel starts colliding with another rectangle at high velocity, from time to time you'll see bumps since it's a "perfect align" to us, not to a physics simulation, with iterations things like these will never be "pixel-perfect".

You will have to convert rectangles to Edge/Loop shapes and then model different physical qualities with hacks like creating artificial tile bounds and then changing properties when character enters a bounding box, but not every physical quality can be emulated that way.

Sooner or later you'll end up writing your own tile-based physics instead of Farseer. If your game doesn't have lots of complex physics puzzles, it will be simpler to abandon Farseer completely and roll your own tile-based physics.

  • \$\begingroup\$ I actually have started coding my own physics engine, specifically for this tiling engine, since it doesn't seem like there's any elegant solutions. \$\endgroup\$ – William Mariager Aug 28 '11 at 14:26
  • \$\begingroup\$ I decided to mark this the answer, as there doesn't seem to be any simple solution, and you'll be better off coding your own solution. Or accept that you can't have different physics and use Marching Squares to make larger bodies. \$\endgroup\$ – William Mariager Aug 28 '11 at 15:19

you can optimize your collisions shapes, this scene can be done with only four rectangles.

you can join correlative boxes to make one bigger.

this video shows it http://www.youtube.com/watch?v=eyhGckHgkkE

when it is adding boxes you can see a light blue rectangle with the optimized shape.

  • 1
    \$\begingroup\$ As I said in the third paragraph, turning a group of objects into a larger object is not an option, as I'd lose individual properties. \$\endgroup\$ – William Mariager Aug 25 '11 at 21:57
  • \$\begingroup\$ you can group them by their phisycal properties too. i think it's not very usual to have a lot of different physical blocks together. \$\endgroup\$ – Blau Aug 26 '11 at 6:19
  • \$\begingroup\$ Grouping them by physical qualities would give me the same problem if the terrain changes a lot on a stretch. It may be unusual, but nonetheless it's what I need. \$\endgroup\$ – William Mariager Aug 26 '11 at 13:58

Hmm... I suspect it might have something to do with your circle and not the tiles beneath it. Try making the ground using a single hull and see if you get the same results. If not, it's the tiles like you suspect. If so, your circle isn't as round as you might think it is.

  • \$\begingroup\$ I did test that. Using one big rectangle there's no issues. \$\endgroup\$ – William Mariager Aug 26 '11 at 0:36
  • \$\begingroup\$ k, Tiles are the issue then \$\endgroup\$ – John McDonald Aug 26 '11 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.