I have a code for recoil, and this recoil rotates the camera upwards, and then returns smoothly back to the starting point.So, when there is a Cinemachine Virtual Camera component on the camera, the view will not be changed by rotating the transform itself, but only by the settings in the virtual camera itself AIM vertical/horizontal value, right ? Then the question is, how to make exactly the same recoil mechanics if the camera needs to be rotated through the Cinemachine virtual camera? This script was supposed to find a camera on the object.Here is the recoil code:

private Vector3 currentRotation;
private Vector3 targetRotation;

[SerializeField] private float recoilx;

[SerializeField] private float recoily;

[SerializeField] private float recoilz;

[SerializeField] private float snappiness;

[SerializeField] private float returnSpeed;

void Update()

targetRotation = Vector3.Lerp(targetRotation, Vector3.zero, returnSpeed* Time.deltaTime); 
currentRotation = Vector3.Slerp (currentRotation, targetRotation, snappiness Time.fixedDeltaTime); 
transform.localRotation = Quaternion.Euler (currentRotation);

public void RecoilFire()

targetRotation += new Vector3(recoilX, Random.Range(recoily, recoilY), Random.Range(recoilz, recoilz));


You must log in to answer this question.

Browse other questions tagged .