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

Vector3 value changes when using just one axis

Discussion in 'Scripting' started by prattmyster, Feb 14, 2022.

  1. prattmyster

    prattmyster

    Joined:
    Apr 15, 2015
    Posts:
    17
    I need help..... again.
    I've got two vector3s both showing y as 0.
    when i go to get just the y values of these vectors the second one(which comes from mouse to world pos) shows as a different number not the 0 it shows in the vector3.

    Anyone got any ideas on whats going on.
     

    Attached Files:

  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,521
    Maybe you are getting confused by what 2.384186E-07 means. It means that value with the point shifted left by 7 places so "0.0000002384186" so pretty much zero.

    If you were to display this with two digits of precision it'd be "0.00".

    This is why you should never compare floats to zero too, you should compare them approximately using Mathf.Approximately etc.

    If you're outputtng strings to the console, you can state the format and include how many digits are shown etc.
     
    prattmyster likes this.
  3. prattmyster

    prattmyster

    Joined:
    Apr 15, 2015
    Posts:
    17
    Thank you makes a lot more sense now, been stressing about this for the afternoon i can continue in peace now :)
     
    MelvMay likes this.