- Home /
Adding some recoil to the Camera (FPS)
I just want to add some recoil to the camera, but I can't find a working script. It's an fps, so I take my mouse axis to rotate the camera. And now I want a pushback to the top, so that the camera looks into the sky after shooting a whole clip. It should be pretty easy, just add some amount to the axis, but it isn't working for me.
I've got something like this from another post, but it just does nothing for me... I got a feeling that my axis is locked in some way, I'm using the "MouseLook" from the standart assets.
transform.Rotate( recoil * Time.deltaTime, 0, 0 ) ;
Update:
This Script is working partially, but I think I reactivate the MouseLook too fast after the Rotate, so that the Mouse just jumps back to the starting position.
mouseLook.enabled = false;
transform.Rotate (-5, 0, 0);
mouseLook.enabled = true;
Answer by Cherno · Mar 31, 2015 at 12:19 PM
You need to disable the mouselook script, or at least the part where the camera rotation is affected by the mouse axis, temporarily while the recoild takes effect, and enable it afterwards. You can use a simple bool for this.
Ok it is working partially, so if I completely disable the script it works, but if i reactivate it after the recoil is done, the mouse jumps back to the starting position. I think i activate the script too fast after the Rotate.
crop the recoil function to it's own routine and add
yield waitforseconds(0.2);
then re enable the script