- Home /
My animations are messed up
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!
Not sure I get it or WHY it is all over the place. In my weapon system I don't change parent I play with visibility. I have a pistol the child of the character's hand, and I have a pistol the child of her hip holster. When weapon is stowed I have the $$anonymous$$eshRenderer of the hand gun disabled and her hip gun meshRenderer enabled. During her "drawgun" animation I have a coroutine to switch the visibility so a few frames into the animation, her hand gun becomes visible and hip gun invisible when her hand reaches the holster where the two guns would essentially overlap
Wow! Thank you, that is a nice idea. Let me get this straight, you have a gun which you use in action, and a gun in the holster. However, I am handling a rifle here. When the rifle is unequipped it stay on the back. However, I'll use the same concept here and I'll update you! Thank you again!
Answer by shadowpuppet · May 03, 2020 at 12:21 PM
@TheMatrixAgent22 .yes, my character also has a rocket launcher she has strapped to her back ( parented to torso) and a rocket launcher parented to her hand. when I do the "draw weapon" animation where she reaches over her shoulder, I have both visible so I can line them up and overlap them at the moment the switch needs to take place ( later I do the code for visibility), then when she has grabbed the weapon and in control of her hand she goes into her pose with the launcher. So launcher, rifle, pistol, whatever - the same technique can be applied. Trickier on a large two handed weapon in that you start by placing the weapon in her hand how you want it for use in idles and shooting etc, and work backwards from that animating the reaching for the weapon and making the two line up for the switch
@The$$anonymous$$atrixAgent22 . sample: http://www.dlavender.com/ROCKET.gif
couldn't upload here so you can see how it looks on that link. I would image for gameplay you would want to be able to access the weapon quickly. So it happens too fast for the eye to catch any transition even if the two don't overlap perfectly.
Don't worry! I know what you mean and how to build it! It's working great without any problems! Thank you so much!
Your answer
Follow this Question
Related Questions
Issue with mecanim playing an animation using setbool 1 Answer
Hello! I have some issues with animations. 1 Answer
Door animation bugs and stays open unity 3D 0 Answers
Imported Blender Animations not Working 2 Answers
Unity Mechanim playing default layer state animation when gameObject is duplicated in the scene 0 Answers