- Home /
How do i make my weapon sway?
Just wondering how i would make my glock sway in the dirrection of the mouse moveing? do i have to animate 4 different ways and it blends them together or is there a simpler way?
               Comment
              
 
               
              Hey, I've done exactly what you said to do, but my gun just goes up above the camera for some reason?
Answer by HSMInteractive · Feb 15, 2012 at 09:59 PM
Yah Just Copy and Paste This Code to The Gun Then Under the GUN Click and Drag Your Gun To It
Code:
 public var MoveAmount : float = 1;
 
 public var MoveSpeed : float = 2;
 
 public var GUN: GameObject;
 
 public var MoveOnX : float;
 
 public var MoveOnY : float;
     
 public var DefaultPos : Vector3;
 
 public var NewGunPos : Vector3;
 
 
     
     function Start(){
 
 DefaultPos = transform.localposition;    
 
     }            
     function Update () {
 
 
     MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
             
     MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
         
     NewGunPos = new Vector3 (DefaultPos.x+MoveOnX, DefaultPos.y+MoveOnY, DefaultPos.z);
     
     GUN.transform.localPosition = Vector3.Lerp(GUN.transform.localPosition, NewGunPos, MoveSpeed*Time.deltaTime);
     
 
      }
WTF i asked this question like 20 $$anonymous$$utes ago and i wouldnt let me ask it!!!
Answer by xixtoxicxzxz · Feb 15, 2012 at 09:59 PM
Here, use this code and under GUN drag your gun to it
Code:
 public var MoveAmount : float = 1;
 
 public var MoveSpeed : float = 2;
 
 public var GUN: GameObject;
 
 public var MoveOnX : float;
 
 public var MoveOnY : float;
     
 public var DefaultPos : Vector3;
 
 public var NewGunPos : Vector3;
 
 
     
function Start(){
 DefaultPos = transform.localposition;    
 
}
function Update () {
     MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
             
     MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
         
     NewGunPos = new Vector3 (DefaultPos.x+MoveOnX, DefaultPos.y+MoveOnY, DefaultPos.z);
     
     GUN.transform.localPosition = Vector3.Lerp(GUN.transform.localPosition, NewGunPos, MoveSpeed*Time.deltaTime);
     
 
}
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                