So I have been playing around with some Javascript to try and get my gun to smoothly aim, but I can’t seem to get it to move from HipPos to AimPos smoothly. Any help would be awesome!
Here’s the Script:
var HipPos : Vector3;
var AimPos : Vector3;
var TimeDamp = 3;
private var MainCam : GameObject;
function Start(){
//setting the HipPos at the game start
transform.localPosition = HipPos;
MainCam = GameObject.FindGameObjectWithTag("MainCamera");
}
function Update(){
if(Input.GetMouseButtonDown(1)){
//if right click move the gun to main cam
transform.localPosition = Vector3.Lerp(AimPos, HipPos, TimeDamp / 150);
//change FOV to align sights correctly
MainCam.camera.fieldOfView = 20;
}
if(Input.GetMouseButtonUp(1)) {
// if right click is released return it to HipPos
transform.localPosition = Vector3.Lerp(HipPos, AimPos, TimeDamp / 150);
//put the camera's FOV back to 60
MainCam.camera.fieldOfView = 60;
}
}