- Home /
How do I calculate world point give a mix of world and local coordinates?
Hi
I got a game object (A) that is put into the world to give an alternative coordination system (which is rotated). I want to be able to calculate the coordinates of other objects (B) to set their y world coordinate to what A's Y coordinate would be if it was at at the B's x and z position (in world space) and its y position = 0 in its local space.
So basicly I want a function that can take a mix of world and local coordinates and return the world position:
// World coordinate will not change, local coordinates will translate into world coordinates.
public vector3 calcWorldPosition(float worldX, float localY, float worldZ);
An example what would be returned would be:
calcWorldPosition(1, 0, 1) -> (1,2,1)
where (1, 2, 1) is world position which is located on the gameobject A's local space (local y = 0)
I've been trying to get this to work, but I've gotten nowhere. Does anyone have an idea of how such a function could be implemented?
Hellium, I have a plane that is rotated. $$anonymous$$y game objects needs to be on that planes y=0. However, the other two coordinates (x and z) still set in the world coordination system.
Also using the Transform.InverseTransformPoint() will not help (at least not by itself). If I convert the coordinates into the "coordination" game object coordinates and set y = 0 and convert back, the y coordinate will still be off due to the "coordination" objects rotation.
Sounds like you want to do the "transform" yourself, but a bit differently from normal. I suggest you break out each member of the transform (position, scale, rotation), and apply(or not) each yourself, manually. Since we are not really clear on what you are looking for, if you break it out into these three transform components, and restate you question with that, we can provide a more concrete answer. (but I suspect you will answer your own question when you do this!)
All that being said, I have the feeling you are going down the wrong track here. It's generally not a good idea to mix up local and global coordinates like that, it can get really confusing. Generally using child objects, and modifying their local/model coordinates as necessary during Update, is what I would suggest.