TheHeadHunter Posted December 24, 2013 Share Posted December 24, 2013 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
50p Posted December 24, 2013 Share Posted December 24, 2013 Simply take away element2 position from element1. local x = x2 - x1; local y = y2 - y1; local z = z2 - z1; -- x, y and z will now be offset, -10, -10, -1 Link to comment
johny46 Posted December 24, 2013 Share Posted December 24, 2013 (edited) 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 December 24, 2013 by Guest Link to comment
TheHeadHunter Posted December 24, 2013 Author Share Posted December 24, 2013 Wow, yeah, now I feel like a moron for asking such an obvious question . Thanks a lot, I don't know why I just didn't think of this earlier... Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now