Search Unity

Transform.forward - only single digit precision

Discussion in 'Scripting' started by Wrymnn, Oct 13, 2019.

  1. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    380
    Not sure if anybody has the same issue, but transform.forward always returns only single decimal point precision vector.

    Example: [0.5, 0, -0.3]

    I am not sure if this is a bug or intended, but it`s completely useless. If you need to calculate exact angle to target that is far away, depending on other`s object facing direction, then transform.forward precision is just not usable.

    Anybody has the same issue? Or do I have some wrong editor settings? float is capable of having far more decimal places than one.
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    i think it depends how you print it into console,
    try printing transform.forward.x ?
     
    hippocoder likes this.
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Like mentioned by @mgear, if that's what you see in the console, it's a truncated representation of the actual value.

    For printing, you can use the ToString overload that takes a format or a format provider, such as ToString("FX"), where X is the number of fractional digits you'd like to see in the console.

    Math etc. will always be done with the actual values of the vectors components, so don't worry about that.
     
    hippocoder likes this.