I wanted to create a situation where a player could have a weapon, a sword, attached to that players hip and on input, allow the player to draw thier sword. This is part of a game prototype I created for a school project. Since time was a concern, All animation clips and models were gathered from Unity's online asset store. Characters and animations - Mixamo's Alpha character package
Simple Medival Sword -  VR
 
To start, after importing the two packages, I droped the character into the scene. Next i droped the sword into scene to gauge size. Once character and Sword were scaled appropriatly, I created three empty game objects, ASword_Prefab(ActiveSword), SSword_Prefab (SheathedSword)  and Player_Prefab. I would then place each empty prefab object with its model object, parent them together, then drag each from heirarchy in my project folder, creating prefabs. My reasoning for this is to keep components like scripts, etc on the parent, while if i change the child, i will not have to re apply components later.
After positioning the swords, i parented them to the hand and hip nodes of the player model. This will allow the sword to follow its particular bone when animation is playing, and not just the character model as a whole. Finally I wrote a script that would enable and disable each sword depending on input, if the character draws the sword or puts it away. The script below is how i could time the animations and turn off the appropriate game object to achieve the player drawing their sword.
Back to Top