Okay, forgive the crude illustration, but it's the best way to demonstrate my problem:
The black boxes are gameObjects, and the red dots are their transform's origin. Likewise the arrows demonstrate their transform's current direction/rotation. I want to find the difference in their x position, according to the bottom left gameObject's transform(red axis). In world coordinates, this would be a number greater than zero, but In my case it should return close to zero, if you get what I'm saying.
Now I thought this would be very simple with transform.right like so:
I also tried:
Neither one gives the correct result. Any ideas? This one is driving me bonkers.
You need to convert the target object's world position to a relative local position, in relation to the source object. You can do this with InverseTransformPoint.
For instance, attach this to object A (the bottom left object):
This means that "localPosB" now contains a vector which represent's object B's position in coordinates relative to object A's orientation and position.
Then, you can get the difference in objectA's local X axis, by simply checking the x component of localPosB, eg:
Hope this works for you!
answered May 18 '10 at 11:10 AM