Reputation: 2684
Now I have rotated the parent cube around 25 degrees wrt to the Y-axis
If we translate the cone 2 units back again, it's not in the original position
What formula do I need to apply to the cone while translating it back to bring it back to it's original position?
Upvotes: 0
Views: 366
Reputation: 482
If you're moving an object using the transform.Translate() method in Unity and you want to stay relative to it's parent, then one way to do this is to pass in the transform of the parent for the Space parameter in Translate.
Like so:
var parent = transform.parent;
transform.Translate(0, 0, 2, parent); // 2. Over here, I have translated the cone for 2 units
parent.Rotate(0, 25, 0); // 3. Now I have rotated the parent cube around 25 degrees wrt to the Y-axis
transform.Translate(0, 0, -2, parent); // 4. If we translate the cone 2 units back again, it's now in the original position
I recreated your issue in a new Unity project and fixed it using the above.
Upvotes: 1