Mixup in global and local positions?
So I have working code, I just have no idea why it works, and as someone just picking up Unity for the first time, it's gonna cause me trouble if I dont understand it.
Basically I'm selecting an object (we'll call it object1) and moving it to the position of another one (object2). So I get object2.transform.position.x, y, and z into a vector3, then set object1.transform.position = thisVector
The problem is, when I do this without either of them using positionLocal, it puts it somewhere unexpected. However, when I instead set object1.transform.positionLocal = thisVector (wherein I got the vector from getting non-local X,Y,Z from object2), it works perfectly as intended.
None of my objects are parents or children to any others, and from what I'm told, local and global should both work the same if the object has no parent? And, more importantly, why do I have to set a positionLocal for the intended effect when I'm inputting another object's non-local position? Or am I somehow getting a local position in the code below?
In case there's some doubt about my code (as there should be since I'm a total noob), here's the copy/paste of the 'working' code, which only works properly once I set object1's transform.localPosition
selectedCoord = new Vector3(_hitInfo.collider.gameObject.transform.position.x, 0, _hitInfo.collider.gameObject.transform.position.z);
_GameManager.MovePiece(selectedCoord);
public void MovePiece(Vector3 _coordToMove)
{
SelectedPiece.transform.localPosition = _coordToMove;
...
Your answer
Follow this Question
Related Questions
Player Prefs not setting the position at start of the game 0 Answers
X coordinates isn't the same on my gameobjects when on same position. 1 Answer
i want to find object x position value at run time please help me 0 Answers
My character moves according to global Vectors 1 Answer
How do you thrust an object to another object's position? 0 Answers