wrld3d / unity-api

Issue tracking for the WRLD Unity SDK
28 stars 8 forks source link

How to Fight Zs: Just teleport! #91

Closed Draco18s closed 6 years ago

Draco18s commented 6 years ago

Step 1: set up the scene, leave the start location alone. It doesn't matter what it's settings are (the default is (37.6058, -122.401)).

Step 2: create this monobehaviour script and attach it to the main camera:

void Start () {
    LatLong newLocation = new LatLong(40.315813, -75.676385); //can be any location, provided it is some distance from the main script's start position
    Api.Instance.CameraApi.MoveTo(newLocation, distanceFromInterest: 800, headingDegrees: 0, tiltDegrees: 50);
}

Step 3: Rotate the camera and watch the Z-Fight commence. More visible in scene view.

z-fight

AubreyF commented 6 years ago

This isn't just a WRLD issue, it's a precision limitation in Unity's rendering depth buffer (and other more subtle systems, such as the physics engine). The commonly implemented workaround is to reset your game world's position in discrete steps to keep the camera relatively near to the origin. Here's a talk on the subject: https://unity3d.com/learn/resources/talks/gis-terrain-unity

malcolm-brown commented 6 years ago

Yep! Some more information is covered on this at https://wrld3d.com/unity/latest/docs/examples/coordinate-systems/ and there's two ways to resolve it with WRLD:

  1. Simply update the Origin Point of the map via Api.Instance.SetOriginPoint(new LatLong(40.315813, -75.676385)); - this repositions the world so that the specified Lat Lon is now at Unity's origin. As mentioned if you keep moving around large distances you'd want to do this regularly.

  2. Switch to ECEF World Space, as described above, which allows for planetary scale movement and works by keeping the camera close to the origin and shifting the world around instead. image.
    This World Space doesn't work well with Unity's default lighting or physics, since the world is now represented as a sphere, so depending on your use case it's probably worth going with option 1.