- Home /
Transform position only working correctly on one axis?
I've never encountered an issue like this before. I'm childing an object to another object on mouse down, and then simply setting the position of that object within the parent, but only the Y position is correct. The X position takes on the Z values, and if I set X to something, the Z position actually takes on that value.
public void OnMouseDown()
{
otherObject.transform.SetParent(parentFab);
otherObject.transform.position = new Vector3(parentFab.transform.position.x, parentFab.transform.position.y - 0.786f, parentFab.transform.position.z + 0.814f);
}
I've tried everything that I can find, clicking on pivot/center and local/global, tried localPosition on everything, adjusted the imported model, moved the object to the position it's supposed to be in before it's even parented, set the parent and grandparent to 0,0,0, removed every single line of code except for just this stripped down OnMouseDown function, and nothing works.
Setting the Z transform to 0 moves it to the correct 0 position (Z) in the parent.
To add more to the oddity is that it seemed to happen out of nowhere, it was working fine one moment, and then decided it had had enough of that and started doing this. I'm missing something really simple, right?
Answer by M_R_M · Nov 10, 2019 at 08:32 AM
In case anyone else experiences the same issue:
The parent object that the child belongs to was rotated on the Y axis 90 degrees, causing the transform positions of the child object to be applied incorrectly. Setting it to 0,0,0 solved the issue.
Your answer
Follow this Question
Related Questions
How to make custom handles take gameobject position offset into account? 0 Answers
How to make object follow touch position?Pls Help 0 Answers
Change position of camera on scene load? 1 Answer
Following another object's position/rotation like parent/child relationship? 4 Answers
How do you set the initial value of a variable to an objects current position in unity? 1 Answer