- Home /
How can I get the rotated position without using Transform in 2D?
I just want to calculate the real/world position within my script. Now I get the original point and direction from my gameobject. I can get the direction of the end point. But i don't know how to calculate specific world position in the game.For excample: when the direction is(1,1),so the right side should be(1,-1).
Answer by davidcox70 · Aug 10, 2020 at 09:09 PM
You can do this with trigonometry, or the lazier way below :-)
In your project, add an empty GameObject as a child of your main game object (I presume the blue circle in your diagram). We'll call the new empty gameObject "reference". Now move it to the center of the cross in your third diagram. When your script references its tranform.position property, it will be report its "real world" position after being moved by the rotation of the parent gameObject. Its tranform.right (etc) properties will also follow the rotation. So (for example) the real world position of where it says "lefT" in your third diagram would be
mainGameObject.Transform.Position-referenceGameObject.Tranform.Right;