Search Unity

Overal precision (ballistics) - non physics question

Discussion in 'Editor & General Support' started by casperjeff, Oct 3, 2014.

  1. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    I've got a pretty good handle on basic techniques and formulas for projectiles - and their adherence to gravity and the ability to 'aim' to hit a target at a distance (and at different elevation). I've been working on several projects with great success - even pretty good predictive aiming (iterative binary search technique taking time of flight into consideration).

    What I noticed most recently is that at longer distances, my accuracy is 'off'.
    I THINK I have ruled out most potential culprits in my code and I am stumped as to where to look next.
    I've even eliminated the physics engine from the equation, as I am drawing the projected path using simple math all based on calculating initial angle based on desired point of impact (applying gravity as appropriate).

    I'm leaning towards throwing my hands up and assuming the issue lies in the limited precision of Vector3 and possibly other Unity elements. I did try switching over to Math (instead of Mathf) trig functions to be able to use double instead of long - but with no effect (as I assume when results are shoved in these lower precision Vector3s, that effort is negated.

    Has anyone ever fought the this type of precision issue in Unity and can lend credence to my theory?

    Thanks in advance....
     
    Last edited: Oct 3, 2014
  2. Valette

    Valette

    Joined:
    Jun 9, 2014
    Posts:
    68
    Not sure if this confirms your theory but I recently spent about days struggling with something similar. I've been creating a physics-based game and, somewhat naively, I set out not realising how non-deterministic computers are, or, at least, non-deterministic between any two machines. For example, sending physics data between a PC and an android tablet, I thought throwing the same projectile with the same force etc, would produce exactly the same results. After about two shots, my two game states looked entirely different, which I now discover isn't news to people who deal with multiplayer regularly but for me was a horrible shock. I'm now sending positional data across the network because I just can't get any two machines to produce exactly the same responses in rigidbodies.

    On reflection, I should have been surprised. I know floating point maths are often approximations of fractional values and can throw up really some strange results. I guess that begins to get amplified the further from the origin you travel. My first ever project was a horizontal scroller and I definitely noticed some strange things happening when I moved too far from 0,0.
     
  3. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Yeah - the non-deterministic nature of the Physx engine is well known - sorry you had to experience it first hand. :)

    I'm fairly certain this is indeed my culprit as well - would love for some gurus to weigh in