- Home /
Question by
Peter 10 · Feb 02, 2011 at 08:48 PM ·
camerapositioncoordinatesrelative
Object coordinates relative to camera
Hi !
I have a litte problem. I have a gameObject that is following my camera. When I print my abject's coordinates I observe they're not relative to my camera but to my world. How can I change that ?
Thanks !
Comment
Best Answer
Answer by Jessy · Feb 02, 2011 at 09:09 PM
http://unity3d.com/support/documentation/ScriptReference/Transform.InverseTransformDirection.html
relativePosition = cameraTransform.InverseTransformDirection(transform.position - cameraTransform.position);
Hahah, You just saved someone! I was looking for that as i am working on a 3d Radar. Thanks!
Best Answer
Answer by Design3.com · Feb 02, 2011 at 09:12 PM
If you make the game object a child of the camera in the hierarchy and use transform.localPosition, you should be able to get it.