Pushing mouse up upon shooting?

I want to push my mouse upwards as the player shoot their weapon, when pressing / holding down the left mouse button… I’m currently following the ETeeskiTutorial on how to create a FPS and I want to add functionallity to it. What I have in mind is something similiar to Counter Strike 1.6 were if you fire your weapon, ie M4A1, the weapon, cam or mouse (I don’t know) is pushing upwards as you shoot simulating Recoil, I guess it is the mouse which is pushed upwards since you can use the mouse to control the recoil…

How is this done? I have recoil on my weapon right now, but all it does is move the weapon backwards towards the player on the Z axis, I want to rotate the weapon upwards slowly but I have no clue on how to do this…

My GunScript.js looks like this. I don’t know if the modification to make it work should be in my GunScript code or in my MouseLook script? Anyways, I will include them both…

GunScript.js:

function Update()
{
	var holdMuzzleFlash : GameObject;
	var holdSound : GameObject;

	currentGunbobX = Mathf.Sin(cameraObject.GetComponent(BobScript).headbobStepCounter) * gunbobAmountX;
	currentGunbobY = Mathf.Cos(cameraObject.GetComponent(BobScript).headbobStepCounter * 2) * gunbobAmountY;
	
	if(Input.GetButton("Fire1"))
	{
		if(waitTillNextFire <= 0)
		{
			if(bullet)
				Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
			
				targetXRotation += (Random.value - .5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, 1);
				targetYRotation += (Random.value - .5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, 1);	
			
			if(bulletSound)
				holdSound = Instantiate(bulletSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
			
			if(muzzleFlash)
				holdMuzzleFlash = Instantiate(muzzleFlash, muzzleSpawn.transform.position, muzzleSpawn.transform.rotation);
			
			currentRecoilZPos -= recoilAmount;
			
			
			waitTillNextFire = 1;
		}
	}
	
	waitTillNextFire -= Time.deltaTime * (fireRate / 60.0);
	
	currentRecoilZPos = Mathf.SmoothDamp(currentRecoilZPos, 0, currentRecoilZPosV, recoilRecoverTime);
	
	if(holdSound)
		holdSound.transform.parent = transform;
		
	if(holdMuzzleFlash)
		holdMuzzleFlash.transform.parent = transform;

	transform.position = cameraObject.transform.position + (Quaternion.Euler(0, targetYRotation, 0) * Vector3(currentGunbobX * ratioHipHold, currentGunbobY * ratioHipHold, 0) + (Quaternion.Euler(targetXRotation, targetYRotation, 0) * Vector3(0, 0, currentRecoilZPos)));
	
	targetXRotation = Mathf.SmoothDamp(targetXRotation, cameraObject.GetComponent(MLookScript).xRotation, targetXRotationV, rotateSpeed);
	targetYRotation = Mathf.SmoothDamp(targetYRotation, cameraObject.GetComponent(MLookScript).yRotation, targetYRotationV, rotateSpeed);
	
	transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
}

MouseLook script:
var inverseLook : boolean = false;

var lookSensitivity : float = 5;

@HideInInspector var yRotation : float;
@HideInInspector var xRotation : float;
@HideInInspector var currentYRotation : float;
@HideInInspector var currentXRotation : float;

@HideInInspector var yRotationV : float;
@HideInInspector var xRotationV : float;

var lookSmoothDamp : float = 0.1;

function Update()
{

	if(!inverseLook) {
		yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
		xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
	} else {
		yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
		xRotation += Input.GetAxis("Mouse Y") * lookSensitivity;
	}
	
	xRotation = Mathf.Clamp(xRotation, -90, 90);
	
	currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
	currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
	
	transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
}

Mouse position is read only, but if you wish to simulate a recoil effect, you can just add to the xRotation after it has been adjusted by the mouse.

function Update()
{
 
    if(!inverseLook) {
        yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
        xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
    } else {
        yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
        xRotation += Input.GetAxis("Mouse Y") * lookSensitivity;
    }
    //Recoil amount is applied to Xrotation. 
    xRotation += recoil;
    xRotation = Mathf.Clamp(xRotation, -90, 90);
 
    currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
    currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
 
    transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
    // Recoil is brought back to 0 over 1 second
    recoil = Mathf.Lerp(recoil,0,Time.time);
}

You can make a float called recoil that you set to some degree, lets say 5 or 10 degrees when you fire, and then let it smooth out back to 0.

 if(Input.GetButton("Fire1"))
    {
        if(waitTillNextFire <= 0)
        {
            if(bullet)
                Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
 // adjust recoil 
recoil = 5;
                targetXRotation += (Random.value - .5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, 1);
                targetYRotation += (Random.value - .5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, 1);    
 
            if(bulletSound)
                holdSound = Instantiate(bulletSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
 
            if(muzzleFlash)
                holdMuzzleFlash = Instantiate(muzzleFlash, muzzleSpawn.transform.position, muzzleSpawn.transform.rotation);
 
            currentRecoilZPos -= recoilAmount;
 
 
            waitTillNextFire = 1;
        }
    }

Warning, uncompiled Code, check for errors.