I am converting a first-person perspective naval simulation project to Unity. The game hinges on scenes in which distant ships might be as far as 20-30,000m away and yet geometry will have to be precisely positioned and represented within feet of the player on his own ship. In conventional terms, using 1 unit = 1 meter, the camera’s near clipping plane would have to be at about 0.2, and the far clip plane about that 20,000 or 30,000 figure.
This means I must keep the camera near the engine’s origin to maintain good floating point precision for the near items, and I must either use a different camera to draw the distant ships than to draw the items on the player’s own ship (so that different clip planes can be used) or I must carefully avoid fine geometry at a distance to avoid Z-fighting. I will leave the issue of two cameras for below and outline how I’ve previously dealt with precision in large coordinate spaces while asking for other ideas.
During previous prototyping on another platform, I found that when my camera was far from the origin, geometry near the camera jittered terribly, wrestling with the granularity of a float, I guess, at the appreciable coordinates where the camera was.
I overcame this by employing a bit of a “hack”. I used the engine’s nominal “world space” as a “scene space”, and my app used a Vector3 to keep track of the “scene offset” – where, in the world, the visible scene was centered. One each Update(), the root objects in the scene graph would be moved, together, to force the camera back to the origin, like so:
static Vector3 sceneOffset = new Vector3();
void Update() {
Vector3 pos = camera.position;
sceneOffset += pos; // scene is now shifted forward
// slide root objects backward in scene graph to place camera back at engine's geometric origin
for (GameObject obj : all_game_objects_with_no_parents)
obj.transform.position -= pos;
}
Depending on the engine, this approach can cause problems with particles that are already emitted (which can get ugly), and some minor things like skyboxes and such have to be ignored (which is not very bad). The nice part of the approach is that you manipulate items in 3-space pretty much as the engine intends you to, and this ensures that any third party scripts would still work fine.
Would this approach work in Unity? A limited test seemed to suggest my ship could be a RigidBody and handle Forces and yet still be something I can shove about by directly forcing its position in Update(). But will I be able to bump particles about in the manner I’d require? Are there other approaches I should consider?
As to using two cameras to render a single scene into the same window, have others done this? I’ve not. I imagine it is done by having one camera with clip planes of near/far of about 10f, 25,000f draw vessels other than the one the player is on and have one of .1f/400f draw his own ship and its equipment.
tone