transform.position inconsistent numbers problem
Couldn't find answer anywhere. I have such script:
if (transform.position.x == 0 {
//aint workin
}
if (transform.position.x == desiredPosition.x) { //desired.x is 0.0 aswell
//aint work in as wale
}
And it doesn't work, even though it should. When I try to Debug.Log transform.position
it gives out "(0.0, y, z)", which is normal. But whenever I do transform.position.x
it gives out weird numbers like "2.328306E-10" even though it is at 0.0x.
I am using CharacterController.Move
to move my character from point to point. Sometimes other locations bug like this aswell, but it is usually 0.0x. I know 100% that the transform is exactly at the desired location, and transform.position
is there to back me up on this, but .x still prints out weird. Any way around this? Can I force move my transform to 0.0x somehow? Any help is appreciated, thanks in advance!
EDIT: I know that float numbers can weird out when you're doing calculations with them wrong, can this be the case here? The Vectors I use to .Move my charController are working and giving out proper values.
Look up all the parts. E-10 is scientific notation. You should also be able to look up how Vectors are rounded when you print them. "unity float precision" will probably get the many, many, many old Qs like yours, which have everything everyone could ever write about it.
Answer by mhT3d · Dec 12, 2015 at 08:18 PM
Simply "2.328306E-10" is a very tiny number which equal 0.0000000002328, it seems like a kind of float numbers wired behaviors, and it is very common when working with UI where you do not get 0.0 but a number like that, so do not take care of it, Go Forward.
Your answer
Follow this Question
Related Questions
Floating Point Error? 1 Answer
C# function with multiple float arguments not working 1 Answer
Is there an int based class/struct like Vector2? 4 Answers
Unity Infinity Math Result 0 Answers
C# Min/Max Rotation based on Float? 1 Answer