Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bizzare, inexplicable, yet reproducible math errors

Discussion in '2D Experimental Preview' started by Xelnath, Oct 26, 2016.

  1. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    402
    Please take a look at this and tell me if this makes *any* sense to you.

    I have the following code:

    Code (csharp):
    1.  
    2.                 float delta = DesiredHoverHeight - GroundDistanceAvg;
    3.                 float upwardDirection = GetUpwardDirection();
    4.                 Vector3 newPost = new Vector3( 0f, delta * upwardDirection );
    5.  
    For the sake of this exercise, upwardDirection returns 1. Delta is some number between 0.25 and 0.75

    In this case, 0.270584

    I would expect to get the result:
    Vector newPost = { 0.0, 0.270584, 0.0 }

    Here's a snapshot from the debugger:

    Screen Shot 2016-10-26 at 2.14.42 AM.png

    WTF? How on earth does newPost return 0, 502, 0??

    I have this at 100% reproducibility - which doesn't even make sense if its a memory corruption issue - and it works at other times, indicating it's not a code issue....

    I am so confused.
     
    Last edited: Oct 30, 2016