Being far away (over 800 studs) from (0, 0, 0) makes aligning parts to the camera impossible

I work on a large open world game with a map size of around 10,000 x 10,000. In my game I have guns that can be aimed and to achieve a zooming effect I set the cameras field of view to a low number (8 - 33). The farther I get from the center of my map when aiming with my guns the more I notice the guns violently shake from any kind of camera movement (scripted movement or user input movement).

~850 studs from (0, 0, 0), very subtle shake:

~6400 studs from (0, 0, 0), very obvious shake;

Both videos were recorded in the same studio play test session. Stripping away all the movement effects boils the positioning logic for guns down to gun.CFrame = camera.CFrame * hardOffset and the shaking still persists.


Camera shake repro.rbxl (20.9 KB)

The repro file below contains none of my games code but uses the same positioning logic from above. The easiest way to see the behavior is by doing the following:

  1. open the repro place and start a test with a player
  2. hold the right or left arrow key to rotate the camera
  3. observe the part aligned to the camera shaking

The repro place comes with the spawn location position at (0, 0, 1000). At 1000 the shaking is hard to see. Position the spawn location further away (0, 0, 6500) and test again to see the shaking be more obvious. For reasons I can’t figure out the shaking is far more noticeable in my game than in the repro place. The only code needed to run the repro is found in StarterPlayerScripts.


I can repro this behavior 100% of the time in studio and in a published game. This has been an observable bug since my game launched in 2017. To the best of my knowledge it is not platform specific.

While this bug exists I cannot hope to have a good user experience with high-zooming firearms in my game. To the best of my knowledge there is nothing I can do as a developer to work around this issue. The bug existing within such a small radius around the origin severally limits my ability to make large games on Roblox.

21 Likes

This bug might be caused due to Roblox’s usage of floating point errors…

also all this text here is Gotham Book on this post, I have the 2.0 brand guidelines on my PC

It would be interesting if we could somehow render objects in the camera’s local space for cases like this. I suppose you could use a ViewportFrame if you really had to.

A common technique game engines use to solve floating point precision problems in huge maps is to offset the entire map locally so your camera is closer to the origin. This technique can also benefit from storing the positions of map objects relative to chunks instead of the world origin. Perhaps this will be addressed someday as more developers create truly massive worlds, but there are a lot of things (like distributed physics) to consider first.

For your case you could probably just switch the decal out with a gui when they zoom in.

1 Like

This just looks like a classic case of precision errors. You can observe this in almost any game (non roblox) that uses 4-byte floats in their matrices when performing multiplications. If you know any OpenGL/DirectX you could easily create a new project in your preferred language and observe this yourself. It’s not fun :confused:

Unfortunately we don’t really have the ability to easily roll out our own data-types, since at the end-of-the-day we have to use CFrames for position.