How to convert between local / world coordinates? – Unity Answers

  1. Home
  2. vector maps manual
  3. How to convert between local / world coordinates? – Unity Answers

I’ve been checking the script reference for: I have a large tilebased map (dynamically generated). I have my levelcam and some objects moving along in this map. But sometimes I need to take the object from the view (which has the camera hierachy as parent) and convert its local relative position into a world/level coordiate so I can freeze it in the map instead of moving it around with the cam. But this makes the object jump to 0,0,0 (which is its normal coord in the hierachy as its child-child-child of a bigger setup I have tried to simplify for example usage. Transform.localPosition returns the local position relative to it’s parent. If an object doesn’t have a parent it’s the same as Transform.position. Transform.InverseTransformPoint transforms a world coordinate into the local space of this Transform. Note that a transformation is not just a position offset. It’s also rotated and scaled according to the parent. Also in most cases you don’t need to convert much. When you change the parent of a Transform it will keep it’s world position (and rotation / scale). It’s automatically converted. If you want to change the parent of an object and move the object to the parents position do either: Okay, thanks for the explanations. I’ll have to check on those facts again then, as I did exactly what you say regarding parent and that made my object jump to 0,0,0 instead of the world pos it was in. I’ve tested the second and it doesnt work. My object goes from cameraview into the local pos of the destination. I need to visually keep the position within the camera to make this effect work. Uhmm, that’s what it should do. As you can read directly above it was an example to move the child object to it’s parent position. I’m still not sure what you actually want to do. If the object should stay in place where it is you don’t have to do anything except changing the parent. Unity will transform everything itself. I get it, but it doesnt work. The child object gets reset to 0,0,0 as its old parent is 0,0,0 in the moving camera setup. I suspect this might be the cause. To understand my problem: I found this illustration. You have a bomberplane. In your camera you view down on earth and in the camera is the nuke hanging. Once you release the bomb (plane still moving), you need to detach the bomb from the plane that moves forward and the bomb needs to stay at the fixed position and then become a child of the ‘world’ its dropping upon… (ofcause a bomb will need to move some forward from its own new world postion and loose altitude too, but for the example) as we dont know when the user drops the bomb, we need to calculate the bombs position in world coords, but its current local pos is 0,0,0 inside the hatch, which also is 0,0,0 inside the plane. But the plane has a world coord. Makes any sense??? :o) You need to use the transform of the OBJECT you want to convert into Worldspace, not the destination parent. Attachments: Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total. Source.

whatsapp button