Question by
BLASTERMASTERR · Sep 06, 2015 at 04:14 PM ·
vector3gunrecoil
How to add recoil to this script?
this is my script and i dont know much about vectors so i cant figure out how to add recoil.
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);
if(Input.GetMouseButton(0))
DefaultPos = -1;
yield WaitForSeconds (2);
DefaultPos = 0;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612015006im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do i just rotate the gun while it should follow the camera? 0 Answers
How To Keep My Weapon With My Camera? 2 Answers
Gun recoil with mouse look script help 0 Answers
Gun recoil? 0 Answers
Vector3.Angle is wrong 1 Answer