Position.z change to -20 when creating item


Is it a bug or is it just a problem somewhere in my code. but when I want to create and Object(Instantiate) but the position.z value automatic change to -20.

Instantiate(crafableItems[slotNumber-1],new Vector3(location.x,location.y,5), new Quaternion(0, 0, 0, 0)).name = "itemInCraftingSlot" + slotNumber;

This is the code I use I even tried to change to z value to 5 when I created it but still didn’t work.
and another question what does Quarernion?


It’s porbably a problem in your code elsewhere.
The Instantiate method (the way you use it here) will create the object at (X, Y, 5) in worldspace. That is because you did not specify a parent object during instantiation. If your object shows to be at Z = -20, then it is probably repositioned later on.

Q: Can you show us a little more relevant code? That might help us explain you what happens.

As for your other question: The quaternion is the rotation of your object. If you want your object to be instantiated with no rotation, use Quaternion.identity, which corresponds to “no rotation”, in stead of new Quaternion(0,0,0,0). That will make it perfectly aligned to the world axes (as your creating the object in world space here).


Koen Matthijs