Problem : transform.position returns vector3 with 1 decimal place

Hi all,

In my game I am adding force to a rigidbody based on the distance of the rigidbody to the floor. The problem is, when I access “transform.position” in code, it returns a vector3 where the X,Y,Z is only 1 decimal place.

For example, from Debug.Log:

(0.1, -0.8, -11.0)

This causes me a problem because the force is then very inaccurate. It’s too powerful and my object ends up pushed below the desired height, and so more force is added to compensate, but this force is also too much, and so my object bobs along continuously.

If I look in the inspector, the transform’s position X,Y,Z show 7 decimal places which is far more accurate.

Is there a reason transform.position is returning 1 decimal, and how can I get more accuracy from it?

Thanks for your help.

Mat

No, the debug log is returning within one decimal place. This is a red herring. You can avoid this behaviour by Debug.Log(myvec.x); for example, but just printing the whole vector3 will round the log output so it fits well on the log.

1 Like

Aha, thank you!

Knowing this, It made it far easier to see my real issue, which i’ve now sorted.

Thanks!

Mat