Hi - I have added recoil into my game as below, it moves up and down at the same speed, what I am looking to do is manipulate it so that on the way down it takes twice as long to reset the camera to its origonal position. However whenever I try manipulate it, it goes twice as far instead of taking twice as long.
The issue is that the camera is rotating per tick by a value, so if you try double or half the value the camera moves further / shorter. Is there a way of manipulating this method of recoil on the (third person) camera so it takes twice as long to reset?
public static void rotateThirdPersonCamera()
{
// reference the game obejcts to manipulate
GameObject cameraRotator = GameObject.Find("CameraRotator");
GameObject player = GameObject.Find("mainCharacter");
float h = _recoilX + _mouseSensitivity * Input.GetAxis("Mouse X");
player.transform.Rotate(0, h, 0);
float v = _mouseSensitivity * -Input.GetAxis("Mouse Y") - _recoilY;
cameraRotator.transform.Rotate(new Vector3(1, 0, 0), v);
// control reset direction of weapon recoil
if ((_recoilState == RecoilState.Resetting))
{
player.transform.Rotate(0, h - _recoilXReset, 0);
cameraRotator.transform.Rotate(new Vector3(1, 0, 0), v + _recoilYReset);
}
if (cameraRotator.transform.rotation.eulerAngles.x < 327.0f && cameraRotator.transform.rotation.eulerAngles.x > 270.0f)
{
cameraRotator.transform.rotation = Quaternion.Euler(
327.0f,
cameraRotator.transform.rotation.eulerAngles.y,
cameraRotator.transform.rotation.eulerAngles.z);
}
if (cameraRotator.transform.rotation.eulerAngles.x > 30.0f && cameraRotator.transform.rotation.eulerAngles.x < 270.0f)
{
cameraRotator.transform.rotation = Quaternion.Euler(
30.0f,
cameraRotator.transform.rotation.eulerAngles.y,
cameraRotator.transform.rotation.eulerAngles.z);
}
Camera.main.transform.LookAt(cameraRotator.transform.position);
}
_smoothRecoil();
}
private static void _smoothRecoil()
{
// smoothing for recoil
if (_recoilState == RecoilState.Moving)
{
_recoilX -= _recoilSmoothing * Time.deltaTime;
_recoilY -= _recoilSmoothing * Time.deltaTime;
}
else if (_recoilState == RecoilState.Resetting)
{
_recoilXReset -= _recoilSmoothing * Time.deltaTime;
_recoilYReset -= _recoilSmoothing * Time.deltaTime;
}
// prevent negative recoil
if (_recoilX <= 0) _recoilX = 0;
if (_recoilY <= 0) _recoilY = 0;
if (_recoilXReset <= 0) _recoilXReset = 0;
if (_recoilYReset <= 0) _recoilYReset = 0;
// configure for resetting animation
if ((_recoilX == 0 && _recoilY == 0) && (_recoilXReset > 0 || _recoilYReset > 0)) _recoilState = RecoilState.Resetting;
// stop the recoil if everything = 0
if (_recoilX == 0 && _recoilY == 0 && _recoilXReset == 0 && _recoilYReset == 0) _recoilState = RecoilState.Stopped;
}
