Question by 
               Enyph-Games · Aug 16, 2016 at 09:26 PM · 
                c#programmingweapontransform.translatetransform.rotate  
              
 
              Programming knife swing
I downloaded a 3d model of a knife from unity asset store, but there is no swing animation. Is it a good idea to code an "animation" that moves and rotates that knife? If it is, can anyone show me how should i do that?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by CausticLasagne · Aug 16, 2016 at 09:38 PM
Personally, from experience it's better to use a Model based animation, especially for a first person game. You can code an animation for sure, but it will never be as clean as an animation.
I'd start with positioning the knife in the player's hand and use something like this:
     [SerializeField]
     GameObject knifeObject;
     // Serializing the field means you can see it in the editor, but it's not public.
     
     void Start ()
     {
         // Assign the Knife Object.
         knifeObject=transform.findChild("Knife").gameobject;
     }
     
     void Update()
     {
         if (Input.getkeydown(keycode.mouse0)) // or attack button
         {
             knifeObject.transform.position += knifeObject.transform.forward;
             knifeObject.transform.rotate (knifeObject.right);
         }
     }
 
               This will do for a start. Add some timers and things to get it right.
CausticLasagne
Your answer