2
\$\begingroup\$

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;
\$\endgroup\$
2
  • \$\begingroup\$ Which transform component is the code referring to? If I'm not mistaken, the default assets are setup so the mouselook script is attached to both the main camera and the player object. The script controls the Y axis on the camera, and the X axis on the player object. \$\endgroup\$
    – Mir
    Commented Mar 27, 2015 at 22:08
  • \$\begingroup\$ Yes you are right with the "MouseLook", my Recoil-Script is attached to the Player Camera, because this should just go up a bit with each shot. That should be correct, because the y-axis of the "MouseLook" is on this Camera too. \$\endgroup\$
    – TobiasW
    Commented Mar 28, 2015 at 12:10

1 Answer 1

0
\$\begingroup\$

you can disable MouseLook for a small amount of time?

using invoke to reactivate after "disableTime"

float disableTime = 0.5f;//0.5 second disable 

void reactivateML() {
mouseLook.enabled = true;
}

    ...
     mouseLook.enabled = false;
     transform.Rotate (-5, 0, 0);
     Invoke("reactivateML", disableTime);
    ...
\$\endgroup\$
3
  • \$\begingroup\$ Yes that works, but the Cursor just jumps back to the starting position if I do that, I think i reactivate the MouseLook Script too fast. I gave you can update in the question \$\endgroup\$
    – TobiasW
    Commented Mar 31, 2015 at 12:38
  • \$\begingroup\$ try invoke to reactivate after deltaTime (see edit) \$\endgroup\$ Commented Mar 31, 2015 at 19:48
  • \$\begingroup\$ I actually didn't use your answer, I just do the recoil part now in the MouseLook Script self, but I set the recoil values in the recoil script. Anyways you brought me on the right path thank you. \$\endgroup\$
    – TobiasW
    Commented Apr 1, 2015 at 12:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .