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…

1 Answer

1

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.