Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Floating Point Precision and Distant Objects

Discussion in 'Editor & General Support' started by I-Vostok-I, Jun 2, 2023.

  1. I-Vostok-I

    I-Vostok-I

    Joined:
    Jul 21, 2022
    Posts:
    1
    Hey, all.

    As a bit of a thought experiment, I've been wondering what it would take to make a large-scale RTS with a key focus on realistic weapon employment, but the issue I'm mentally hung up on is Unity's (and many other engines') floating point limitations. I understand that the most common way to deal with the issue is to shift the origin as the player/camera moves, and/or to segment the world into a grid, but I don't see how those methods would help in a situation where two objects need to simultaneously exist and are separated by a distance much greater than Unity's practical space limits.

    For example, real-world surface to air missile systems, such as the Patriot and S-300/400, work with distances in excess of 100km, however, with Unity losing precision after just a few kilometres, getting a virtual Patriot to shoot at a virtual aircraft at those sorts of ranges seem impossible unless the engagement takes place entirely within a script and only one half of that engagement is actually rendered at any one time.

    My question is: Is there an accepted solution for this sort of problem in engines which use 32 bit floats, or is the only real solution an engine that uses 64 bit floats?
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    What's your aim? Show the deployed missile somehow? If you plan to zoom out to show the missile in its path, zoom out the resolution too. You can show the object within the acceptable boundaries and at the same time you can keep tabs what region it's really in. It's a bit similar to relative rendering. Or you can use doubles instead of floats for keeping "real" positions and render them relative described above.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    I think if you wanted to model the entire lifecycle of the missile's flight along with accurate aiming and guidance systems and have it track all the way to another target that was distant enough to cause issues with a
    float
    , your only option is to move to higher precision, such as
    double


    Remember that games are almost universally a Potemkin village, all smoke and mirrors, pay no attention to the man behind the curtain. Your job as a game designer and a game engineer is to come up with a solution that gives the desired experience. If you really want to simulate everything perfect, that leaves far less room to maneuver.