How to fix model glitching when far away from origin

I’m currently working on an endlessrunner where I am getting further and further away from the origin. I have the problem, that my models start to have this weird glitch effect around them when I am far away from the origin. I made this playground(Babylon.js Playground) to demonstrate the issue. After about 10 seconds the cube starts to shake and it only gets worse from there. What can I do to fix this?
Thank you in advance :slight_smile:

Hey,

It feels like an issue with JS precision :slight_smile: Try scaling down the scene and not get to the 300000 - 500000 units region. You can also try “resetting” the world from time to time (move everything “back” and reset the player’s position to 0 to make sure this doesn’t happen.

Hey. Thank you for your reply. Shouldn’t this then be classified as a bug? And resetting is sadly rather difficult in this case because of the way I generate where the player moves. But thank you!

A bug? we are doing whatever we can with the environment we are at :slight_smile:

It is not a bug, it is an expected behavior. Javascript doesn’t have integers. only doubles. and it does all of its arithmetics using doubles instead of ints. Look at the answer js provides:

image

And as we do quite a lot of calculations internally, there are side effects.

There are even issues with smaller numbers:

image

thou they are, in general, more exact.

Not a bug, a feature. of your browser :slight_smile:

1 Like

Good old floating point errors… Well thank you and I’ll just try to have the player loop back to the origin. Have a nice day!

1 Like