Search Unity

is transform.forward rounded off?

Discussion in 'Scripting' started by BillyMFT, Oct 13, 2015.

  1. BillyMFT

    BillyMFT

    Joined:
    Mar 14, 2013
    Posts:
    178
    Hi there,

    I'm using transform.forward to get the direction an object is facing. When I Log out the value I get xyz with 1 decimal place. eg

    (0.1, 0.3, 1.0)

    Is it actually more accurate than this? I'm get some issues when I multiply it and I'm wondering if this might be the problem. For example, when I rotate the object a bit I would expect the value to go to

    (0.1, 0.3555, 0.9555)

    but it jumps straight to

    (0.1, 0.4, 0.9)

    Hope that makes sense. I'm really tired.

    Thanks
    Bill
     
  2. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    The logging will be truncating the precision, try adding this:

    Code (CSharp):
    1. Debug.Log(transform.forward.ToString("F2"));
    F2 means "format the string to 2 decimal places" etc.
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    yes, and you can also see more exact value by printing them separately vec.x, vec.y, vec.z
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    they are floating point values, so there is always going to be some inaccuracy thanks to that... just something to bear in mind when working with vectors.
     
  5. BillyMFT

    BillyMFT

    Joined:
    Mar 14, 2013
    Posts:
    178
    excellent. Thanks very much.