Hi Unity Hivemind, Need some help trying to figure out what is going wrong in my project.
When I launch my game I can have my character start holding a sword:
GameObjectsword=Instantiate(Resources.Load(“MyPrefabs/gear/sword-simple 2”,typeof(GameObject)))asGameObject;
EquipRightHandWith(sword);
I’m trying to make it so the character can walk over the item and auto equip it so i moved that code out of void start into a new EquipTestItem void
This is the code i use to walk over the item and equip it
publicvoidEquipRightHandWith(GameObjectweapon){
weapon.transform.parent=HookRightHand.transform;
Vector3offset=weapon.GetComponent().positionOffset;
weapon.transform.localPosition=Vector3.zero+offset;
The weapon will be added, and have the right rotation but is out in front of the character. I figured it might be because it is not updated properly so I added this before the local position:
weapon.transform.position=HookRightHand.transform.position;
weapon.transform.rotation=HookRightHand.transform.rotation;
That causes the weapon to move under the hand and have the wrong rotation and position. I can disable all of this and start the character with the weapon auto equipped ensuring that the weapons offset/rotation/position are correct, but I cannot get the item to snap properly while the character is in motion.