9
\$\begingroup\$

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?

\$\endgroup\$
6
  • \$\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\$ Commented Aug 25, 2011 at 19:02
  • \$\begingroup\$ @Doug: I just tested that, and it didn't make any difference. \$\endgroup\$
    – William
    Commented Aug 25, 2011 at 21:21
  • \$\begingroup\$ Are the ground tiles static bodies? \$\endgroup\$
    – bummzack
    Commented Aug 26, 2011 at 6:19
  • \$\begingroup\$ @bummzack: Yes they are. \$\endgroup\$
    – William
    Commented Aug 26, 2011 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
    Commented Aug 28, 2011 at 5:48

3 Answers 3

5
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\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
    Commented Aug 28, 2011 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
    Commented Aug 28, 2011 at 15:19
0
\$\begingroup\$

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.

\$\endgroup\$
3
  • 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
    Commented Aug 25, 2011 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
    Commented Aug 26, 2011 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
    Commented Aug 26, 2011 at 13:58
0
\$\begingroup\$

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .