Quantcast
Channel: Latest Questions by dhendrix
Viewing all articles
Browse latest Browse all 42

Finding difference between gameObject's x coordinate according to one object's transform

$
0
0

Okay, forgive the crude illustration, but it's the best way to demonstrate my problem:

alt text

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:

var diffX = transform.position - other.transform.position;
diffX = Vector3.Scale(diffX ,transform.right);

I also tried:

var tempF = transform.position.x - other.transform.position.x;
var diffX  = Vector3(tempF, 0 ,0);
diffX = transform .TransformDirection(diffX);

Neither one gives the correct result. Any ideas? This one is driving me bonkers.


Viewing all articles
Browse latest Browse all 42

Trending Articles