- Home /
Aim down sights ( javascript )
So i have my own javascript on the scope effect ( zooming in ) , but i want to play an animation or by code to look down the sights if my FOV has increased.
public var Aim : boolean = false;
public var deffFOV : float;
public var CAM : GameObject;
function Start () {
deffFOV = CAM.camera.fieldOfView;
}
function Update () {
if(Input.GetMouseButtonDown(1)){
Aim = true;
}
if(Input.GetMouseButtonUp(1)){
Aim = false;
}
if(Aim) {
CAM.camera.fieldOfView = Mathf.Lerp(CAM.camera.fieldOfView, FOVIN , FOVspeed * Time.deltaTime);
}
if(!Aim){
CAM.camera.fieldOfView = Mathf.Lerp(CAM.camera.fieldOfView , deffFOV , FOVspeed * Time.deltaTime);
}
}
EDIT (MOD): It seriously doesn't take more than 2 minutes to fix up the code. Please do so yourself next time you're asked to :)
Please take out those redundant spaces from your code, it will look better :)
I still need to edit it , then once im done ill get rid of them .. :p
Answer by contactotalkzer · Apr 26, 2018 at 12:16 AM
Wouldn't be mush easier to make a lerp? if(Input.GetMouseButton(1) && !isReloading && canShoot && m_player.correr == false) { transform.localPosition = Vector3.Lerp(transform.localPosition, aimPosition, Time.deltaTime * adsSpeed); } else { transform.localPosition = Vector3.Lerp(transform.localPosition, originalPosition, Time.deltaTime * adsSpeed); }