Hi Everyone,
I have a problem with Lerp, I want smoothly move between two points in local position and i can’t understand why my code not working. Please help me.
Here is my code:
public Vector3 HipPose;
public Vector3 AimPose;
public float AimingZoom = 50f;
public float AimSpeed = 5.0f;
private GameObject MainCam;
private GameObject GunCam;
void Start ()
{
transform.localPosition = HipPose;
MainCam = GameObject.FindGameObjectWithTag("MainCamera");
GunCam = GameObject.FindGameObjectWithTag("gunCamera");
}
// Update is called once per frame
void Update ()
{
if(Input.GetKey(KeyCode.Q))
{
MainCam.camera.fieldOfView = AimingZoom;
GunCam.camera.fieldOfView = AimingZoom;
transform.localPosition = AimPose;
transform.localPosition = Vector3.Lerp(transform.localPosition, AimPose, AimSpeed * Time.deltaTime);
}
if(!Input.GetKey(KeyCode.Q))
{
MainCam.camera.fieldOfView = 60;
GunCam.camera.fieldOfView = 60;
transform.localPosition = HipPose;
transform.localPosition = Vector3.Lerp(transform.localPosition, HipPose, AimSpeed * Time.deltaTime);
}
}
robertbu, thank you so much, now all works properly. Have a nice day. :)
– gigs