Do large offsets matter?

Topics: User Forum
Jun 18, 2010 at 8:02 AM

Hey,

I'm currently using your engine and it works out really nice, except for one aspect. I have a sidescroller with a car going from left to right over a landscape. At a distance of about 30000 the collision accuracy with the terrain deteriorates, leading to the car sinking into the ground, balancing on the front and so on. Here are the parameters:

Farseer physics 2.1.3
Collider: SAT (worked out best)
Car: Modelled as a simple shape made out of vertices
Terrain: Also a single shape made out of vertices with small hills

I looked up the source code and searched for a section in the collision detection code where relative values where used, which would explain that behaviour at large distances. Unfortunately I didn't find any.
I have thought of two possibilites:

a) Wind the landscape in a large circle around 0,0 and adapt the gravity according to the point where the car is located (tremendous effort)
b) Scale, but this is now solution as in endless game these distances can still be reached

Can you think of another possibility or even the reason for this behaviour? Thanks in advance!

Regards

Mattes

Coordinator
Jun 18, 2010 at 5:25 PM

As you already mentioned, floating point inaccuracies could be a factor when working with huge distances. I'm not sure that is the only factor in this case.

The engine was never built to cope with HUGE worlds, but the fix is pretty simple. Scale your physics world to be smaller than the drawn world.

Developer
Jun 19, 2010 at 8:48 PM

Or change everything in the engine to use doubles!!!

 

Jun 20, 2010 at 12:47 PM
Edited Jun 20, 2010 at 1:06 PM

Thanks for your help!

As mentioned in my post, scaling is not an option as in endless mode the player can travel arbitrary far. Changing everything to doubles sounds like a plan, but if the reason for this behaviour is not due to FP inaccuracies, it won't work. I give it a try if my new option c) turns out to be too time-consuming: The starting player position will be at -10000 and each time it reaches +10000 I will reset the player. This resetting fortunately fits into my game design.

Thanks again!

Mattes