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

When passing float to Vector3 it is taking only one digit after decimal

Discussion in 'Scripting' started by MSSK15, Oct 5, 2020.

  1. MSSK15

    MSSK15

    Joined:
    Mar 30, 2017
    Posts:
    19
    Hi,
    I am building a simulation application based on Geo location which should be very precise. Here for example i have latitude and longitude values as 17.310529, 78.455506. when print these in log am getting same values . but when i pass them to vector3 it is taking only one digit after decimal (Like 17.3 and 78.4). In my application i want very precise values to place game-objects.
    How to get the same exact values in Vector3.
    Attached an basic snap (Not from my project:D) (Link for snap)
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    A Vector3 contains 3 floats so will be set to those digits. However, when you Debug.Log a vector3, the debug code will round the values it displays if you just pass a vector3. You could pass the separate floats if you want to see what they are. Like so;
    Code (CSharp):
    1. Debug.Log("X: " + myVec.x + " Y: " + myVec.y + " Z: " + myVec.z);
     
    MSSK15 likes this.
  3. iMobCoding

    iMobCoding

    Joined:
    Feb 13, 2017
    Posts:
    160
    Don't worry, your floats are passed exactly as you want. It's just how Unity shows log for Vector3. Try printing vector.x and you'll see everything is there...
     
    MSSK15 likes this.
  4. MSSK15

    MSSK15

    Joined:
    Mar 30, 2017
    Posts:
    19
    Thank you. it worked.