I have a weapon animation system in place. It’s on the 3rd layer, because I need to control the body and the arms too. When I don’t have it equipped, I change the parent (of the weapon) to the FPSController (biggest parent), because then the weapon doesn’t move with the body. When I equip it, the parent is changed to the neck, so that the weapon moves with the camera (camera attached to head which is attached to the neck). I can’t really show you what happens, but the weapon is just EVERYWHERE but where it is supposed to be. Here is my code that controls that:
if (Input.GetButtonDown("Slot" + slot) && !weaponEquipped) {
weaponGO.transform.SetParent(playerNeck.transform);
animator.Play("equip" + weapon, 2);
animator.Play("equipArms" + weapon, 1);
weaponEquipped = true;
} else if (Input.GetButtonDown("Slot" + slot) && weaponEquipped) {
weaponGO.transform.SetParent(gameObject.transform);
animator.Play("unequip" + weapon, 2);
animator.Play("unequipArms" + weapon, 1);
if (!AnimationIsPlaying(animator, "unequip" + weapon, 2))
weaponEquipped = false;
} else if (!weaponEquipped && !AnimationIsPlaying(animator, "unequip" + weapon, 2)) {
animator.Play("idle" + weapon, 2);
} else if (!AnimationIsPlaying(animator, "equip" + weapon, 2) && weaponEquipped) {
animator.Play("equippedIdle" + weapon, 2);
}
This function is placed in Update(), and here is my animator layer.
I can confirm that the system works without the parent change and I also did change the animations according to the parents.
I hope someone can help me! Thank you so much!