- Home /
Add vector according to objects's local position & roation
How can I add, say a Vector3 [say: (0,0,1)] in relation to another object's rotation and position?
Because if I do something of the sort:
desiredposition = anotherObject's + new Vectro3(0,0,1);
If will add it in relation to the world space. But what I want is to find in relation to the other object(taking into account its position, and its rotation. So If the other object rotates, the new point will be somewhere else....
Answer by Dave-Carlile · Jul 01, 2016 at 03:44 PM
The Transform class contains some properties for this.
Transform.forward gives a world space vector pointing in the direction the object is rotated. Transform.right
and Transform.up
give similar vectors for the other directions.
So otherObject.transform.position + otherObject.transform.forward * 10
will give you a position 10 units in front of otherObject
based on the direction that object is facing.
Your answer
Follow this Question
Related Questions
How to get offset postition after rotation ? (Spent hours figuring it out) 3 Answers
RTS Camera movement wrong after rotation 1 Answer
Player not facing the mouse correctly 1 Answer
Setting value of transform.rotation in code, C# 2 Answers
Determine new position from magnitude & rotation/heading 1 Answer