Hi, I am a beginner, and I have a GameObject rotated 270 degrees. I want to move some other objects to the right of the first object, to its local X-Axis.
What I have tried:
secondObject.transform.position = firstObject.transform.position + Vector3.right * desiredDistance;
secondObject.transform.position = firstObject.transform.position + firstObject.transform.right * desiredDistance;
secondObject.transform.position = firstObject.transform.position + firstObject.transform.TransformDirection(new Vector3(desiredDistance, 0, 0));
I tried similar things with TransformPoint
and InverseTransformPoint
The second object didn’t move to the X-Axis, right or left at all
Any help will be appreciated, thank you for your time in advance.
This should work, but you need to make sure you’re actually rotating the object on the Y axis. I can imagine you’re rotating it on either Y or Z axis, but you want the 2nd object to be on the end of the “X axis” dial/arrow.
firstObject.transform.right
is technically the same thing as
firstObject.transform.rotation * Vector3.right
so it takes into account the current rotation quaternion.
Hi and thank you for your time.
I finally found the problem, and it turns out I was calculating the distance I wanted the objects to move on world space and not local. The distance they were supposed to move was based on BoxCollider.size.x
. I didn’t know that the collider size
vector wasn’t in local space. I just had to use TransformDirection()
on it.
1 Like