Jump to content

Relative Element Positions


TheHeadHunter

Recommended Posts

Greetings,

I come to you today with a very interesting question, imo. I need a way to get an element's position, relative to that of another.

Example:

element1's absolute ( world ) position is x:100 y:100 z:4.

element2's absolute position is x:90 y:90 z:3

So, my question is, how can I get the coordinates of element2, relative to those of element1? Meaning, the relative coords 0;0;0 will be at 100;100;4 absolute. And element2's coords should be -10;-10;-1 relative.

I hope I was clear enough in my explanation of what I need...

Edit: In case you're wonder why I just don't do what I'm planning with absolute, it's because it will involve vehicles which will move around, so it's not really an option. Also, sorry for the lack of code, but it's more of a theoretical question than anything.

Link to comment

Well... Have you tried just subtracting the coordinates from each other? Like this:

relX = x1 - x2 
relY = y1 - y2 
relZ = z1 - z2 

Depending on the order you subtract, you'll get relative position of pos1 according to pos2, or relative position of pos2 according to pos1.

---

It appears 50p was faster ;)

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...