I am trying to get a good camera recoil system in Unity, but what I have tried so far doesn't seem to look very good. My current method, is using Quaternion.Lerp. With the way I have my shooting system set up, the camera recoil going up all happens within one frame, so when you shoot faster, it tends to look choppy, whereas the recoil going back down is smooth and normal. My question is, is there a better way to handle the camera recoil, while keeping the same look and effect, but having it look much more smooth? I have a quick video to show how the camera recoil looks (watch as the camera moves upwards) https://www.youtube.com/watch?v=HsS0rtoj9l4
And here is the part of my code that handles the camera recoil
void Update () {
Recoil2();
Vector3 cameraRecoil = weaponSettings.CurrentWeapon.cameraRecoil;
Transform cameraClimb = generalSettings.cameraClimbHolder.transform;
string fireMode = weaponSettings.CurrentWeapon.fireMode.ToString();
if (fireMode == "Semi")
if (Input.GetButtonDown("Fire1"))
Shoot();
else
CameraRecoil1 = Vector3.Lerp(CameraRecoil1, new Vector3(0, 0, 0), Time.deltaTime * cameraRecoil.z / 10f);
if (fireMode == "Auto")
if (Input.GetButton("Fire1"))
Shoot();
else
CameraRecoil1 = Vector3.Lerp(CameraRecoil1, new Vector3(0, 0, 0), Time.deltaTime * cameraRecoil.z / 3f);
}
void Shoot ()
{
if (shoottime <= Time.time && !isBusy && !isReloading && !isRunning)
{
shoottime = Time.time + weaponSettings.CurrentWeapon.fireRate;
WeaponInfo currentWeapon = weaponSettings.CurrentWeapon;
Transform cameraClimb = generalSettings.cameraClimbHolder.transform;
Vector3 cameraRecoil = weaponSettings.CurrentWeapon.cameraRecoil;
CameraRecoil1 = Vector3.Lerp(CameraRecoil1, new Vector3(-cameraRecoil.x, Random.Range(-cameraRecoil.y, cameraRecoil.y), 0), Time.deltaTime * cameraRecoil.z);
}
}
void Recoil2 ()
{
Vector3 cameraRecoil = weaponSettings.CurrentWeapon.cameraRecoil;
Transform cameraClimb = generalSettings.cameraClimbHolder.transform;
cameraClimb.localEulerAngles = CameraRecoil1;
}
Anyone have any ideas? I appreciate anyone who can help me!