Search Unity

Positional issue. ??

Discussion in 'Scripting' started by renman3000, Nov 19, 2014.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi there,
    I am getting an odd occurance that I cant explain.

    My transform, is shown in the inspector with a y pos of 3.75, correctly.

    However, my print out, later when I ask is 3.8, despite clicking on the transform and the inspector showing 3.75.

     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Ok, so is this true, the console position prints only to 1 decimal point?
     
  3. GetUpKidAK

    GetUpKidAK

    Joined:
    Apr 9, 2013
    Posts:
    84
    Have you tried just the y value to verify? Floats certainly aren't rounded that much.
     
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    That's what the toString() method does. But there's also an overload which takes a string as argument.
    Try to put 'f5' or 'F5' in, it should print the values with higher precision.
    Just a little more work as you always have to explicitly call 'toString("...")', but that shouldn't be the problem.
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Yes, the console only prints one decimal for Vector3's.
     
  6. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Have you tried using the overload with the string parameter? You can pass "f2", "f3" and so on.
     
  7. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
     
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Vector3 print function only prints to a decimal for logging purposes. To print them fully, you should create or overload for your own detailed printing. Debug.Log(thing.x) will print the full precision. This is normal.
     
  9. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Again.

    Should have wrote solved.
    So, thread solved. Cheers!
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This has come up a lot, you could have searched it :p
     
  11. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I may have misunderstood your answer to my question, but with
    Code (CSharp):
    1. private Vector3 v3 = new Vector3(34.32131f, 1, 34.32131f);
    2.     void Start()
    3.     {
    4.         Debug.Log(v3.ToString("f6"));
    5.     }
    i get:



    so you can make it print more decimals. oO
     
  12. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Oh, nice one!