I’m having a nightmare of a time solving this issue.
I have a character model, with a hand bone. In my game I will need to attach variety of different weapons to this hand bone, so I need a method of making sure the weapons attach properly, facing the right direction/rotation when they stick in the hand.
I’ve started by trying to get my first weapon to equip properly, however no matter what trick I try, the weapon will not listen when being instantiated.
So far what I’ve done is put the weapon in the models hand attached to the hand bone as its child, and while its there I set the rotation and position of the sword to make the sword fit perfectly in the hand, then saved those rotation and position values in the prefab, and then saved the values again in 2 variables on the item.
Instance 1:
EquippedWeapon = (GameObject)Instantiate(Resources.Load<GameObject>("Weapons/" + itemToEquip.ObjectSlug), playerHand.transform.position, playerHand.transform.rotation);
EquippedWeapon.transform.SetParent(playerHand.transform);
This properly equips the weapon to the hand as its child, but it is offset a bit and hanging off of the model, not using the prefabs rotations, so I then decided to put the prefabs rotation and position values directly into variables on the weapons interface,
public Quaternion defaultrotation{ get; set; }
public Vector3 defaultposition{ get ; set; }
public void Awake()
{
defaultposition = new Vector3(-2f, 0.082f, 0.131f);
defaultrotation = Quaternion.Euler(-52.512f, 65.29501f, -63.275f); }
And then I call on these values after the parent is set for the weapon after it has bee instantiated:
EquippedWeapon = (GameObject)Instantiate(Resources.Load<GameObject>("Weapons/" + itemToEquip.ObjectSlug), playerHand.transform.position, playerHand.transform.rotation);
EquippedWeapon.transform.SetParent(playerHand.transform);
EquippedWeapon.transform.rotation = EquippedWeapon.GetComponent<IWeapon> ().defaultrotation;
EquippedWeapon.transform.position = EquippedWeapon.GetComponent<IWeapon> ().defaultposition;
Millions of games attach different weapon models to a models hands with perfect rotation and position, and everything I’ve found online simply tells me to attach it to the bone, which I’m doing. What do I need t
but this is sending the sword into Africa. I am a bit new to unity, and there’s clearly some sort of interaction I’m messing up here, but I’ve spent the better part of an evening and I can’t solve this.
Millions of games attach different weapon models to a models hands with perfect rotation and position, and everything I’ve found online simply tells me to attach it to the bone, which I’m doing. What do I need to do to get the sword to equip to the hand parent in the correct position? is it possible with script or do I need to change something with the sword? plx halp