This is driving me insane - gameObject.transform.position gives the world relative position of the object, right?
I’m trying to get the distance between two transform.position, and the distance is zero when they are not even overlapping.
In the below image, the two objects I’m comparing distance between their transform.position are “Player_Chef” and “CashStack test”. I’ve selected the Player_Chef to show you the origin point, and the component “Cash Transfer” attached is the one printing to the Console the line
distance: 0.6426157, cashStack: (13.10, 0.00, 52.80), cashTransfer: (13.50, -0.08, 52.30)
and the code in this script to get the distance is
float distance = Vector3.Distance(cashStack.transform.position, gameObject.transform.position);
Note the distance reported is just about zero, the positions are similar, and yet visually, they are nowhere near each other.
Here’s another screenshot with the “CashStack test” object selected, to prove the origin is in the center, you can see the move gizmo is centered on the green stack of cash;
And here’s a 3rd image to show what happens to the distance when I actually move the player on top of the object - the distance grows to “9”, and the positions become more different:
Now, it’s true the Player prefab is set up weird and not ideal (I’m a contractor newly placed on the team so I can’t do much about this), the player object is nested in another prefab and moves around internally relative to that prefab.
But regardless of what wacky nested prefab they have set up, the position given for transform.position for either object should be giving me the correct world position to get a distance between, right?? So what’s going on here??




