Unexpected Vector2.Distance results
Hi all, I'm trying to get the 2d distance between a wheel's connected Anchor Point and the wheels actual transform position.
This is my code:
float check_distance = Vector2.Distance(myWheelHinge.connectedAnchor, new Vector2(myWheel.transform.localPosition.x, myWheel.transform.localPosition.y));
Debug.Log("Anchor" + myWheelHinge.connectedAnchor + " TransformX:" + myWheel.transform.localPosition.x + "TransformY: " + myWheel.transform.localPosition.y);
Debug.Log(check_distance + myWheel.name);
so check_distance is a vector2.distance of my connected anchor vector2 and my wheels local transform position's x/y. The "check_distance" this produces is massively inconsistent. I'd expect it to be usually small(sub 0.1)
but:
Log output:
"Anchor(-0.6, -0.4) TransformX:-0.5669999TransformY: -0.3689995"
(the difference is about -0.04, -0.04)
"check_distance"= 6.664002E-08Wheel_L
and the next step(s)
5.960464E-08Wheel_L
1.884864E-07Wheel_L
if I move the wheel away from the anchor position, these numbers don't seem to change. (i'm getting results anywhere between 0.1 to 9)
What I want to do is detect if a wheel is too far away from it's connected anchor and 'relocate it' back
does this make any sense? :D
Comment
Your answer