- Home /
How to define a position local to an object?
Hi
I want to define a position which is 10 units along an object's x-axis. The following sets the position along the world x-axis, how to I modify it for the object axis?
var newPosition : Vector3;
newPosition = myCube.transform.position;
newPosition.x += 10.0;
(I'm not trying to move myCube, I want to instantiate something at the new position)
Thanks
Steve
Answer by Mike 3 · Jul 01, 2010 at 09:36 AM
TransformDirection is a handy function to change a local offset into a world offset:
myCube.transform.position = myCube.transform.position + myCube.transform.TransformDirection(Vector3(10, 0, 0));
Do you realy need the additional "myCube.transform.position +"?
yes - position + offset = new position, same as yours - the only difference is that it's an offset in local coordinates
Ahh understand. 3Dimensional Vectors sometimes confuse me.
$$anonymous$$any thanks, TransformDirection works exactly as needed.
Just for completeness - you also have InverseTransformDirection if you want to go the other way
Answer by Case23 · Jul 01, 2010 at 09:30 AM
myCube.transform.position = myCube.transform.position + new Vector3(10, 0, 0);
should do it.