The script is intended to rotate my Gun on the x angle when I move my mouse horizontal. My script works fine as long MoveOnX is positive, But when its negative, it changes the x, y and z rotation. Can someone help me?
GunMovement.js
public var MoveAmount : float = 1;
public var MoveSpeed : float = 2;
public var GUN: GameObject;
public var CAM: GameObject;
public var MoveOnX : float;
public var MoveOnY: float;
public var DefaultPos : Vector3;
public var DefaultRot : Vector3;
public var NewGunPos : Vector3;
public var NewGunRot : Vector3;
public var ONOff : boolean = false;
function Awake(){
DefaultPos = transform.localPosition;
DefaultRot = transform.localEulerAngles;
ONOff = true;
}
function LateUpdate () {
if(ONOff == true){
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);
NewGunRot = Vector3 ( DefaultRot.x + MoveOnX * 800, DefaultRot.y, DefaultRot.z);
GUN.transform.localPosition = Vector3.Lerp(GUN.transform.localPosition , NewGunPos, MoveSpeed * Time.deltaTime);
GUN.transform.localEulerAngles = Vector3.Lerp(GUN.transform.localEulerAngles , NewGunRot, MoveSpeed * Time.deltaTime);
}
else{
ONOff = false;
GUN.transform.localPosition = Vector3.Lerp(GUN.transform.localPosition, DefaultPos , MoveSpeed *Time.deltaTime);
}
}