Hello all
Having a problem with instantiating models onto my character.
I use an item DB which ive made that has an objects rotation as X|Y|Z in a string.
When an items searched for, the item manager gets all the info and splits rotation into different variables. Then from the manager I can get data easily about all items quickly using db.findItem(ID); then using db.VARIABLE to get info.
But when I instantiate the object to an empty game object on my characters head when equipping an item from the inventory, the item has random transform.position/rotation values even though I set them after instantiating as a variable. itemToEquip is set when I click on an inventory button, it fetches the object using
itemManager/DB
thisObject = Resources.Load(db[i+10], GameObject);
db[i+10] = armor/objects/OBJ_test (path to where I store the game object in resources folder)
This all works fine and the object does appear on the characters head as a child all this works perfectly.
I use the code below to split the rotation info of the item which I get from the itemDB array so I can set them specifically for each item
rotationString = db[i+11]; // X|Y|Z
rotSplit = rotationString.Split("|"[0]);
rotX = parseFloat(rotSplit[0]);
rotY = parseFloat(rotSplit[1]);
rotZ = parseFloat(rotSplit[2]);
This all works fine and the data shows up in itemManager when I search for specific items.
Below is the code I use to instantiate my objects onto the character. Does anyone notice anything that might be wrong? No matter what I set the rotation data to it never seems to be applied to the model?
var equipRotation = Quaternion.Euler(db.rotX, db.rotY, db.rotZ);
var itemsObj2 = Instantiate(itemToEquip, equipmentHead.transform.position, equipRotation);
itemsObj2.transform.SetParent(equipmentHead.transform);
At first I tried this without using equipRotation and just getting the pos/rot of the parent but it still wasnt set to the same
var equipRotation = Quaternion.Euler(db.rotX, db.rotY, db.rotZ);
var itemsObj2 = Instantiate(itemToEquip, equipmentHead.transform.position, equipmentHead.transform.rotation);
itemsObj2.transform.SetParent(equipmentHead.transform);
I have just noticed that the object always seems to face the same way in the world rather than as the parents rotation