Weapon Recoil

Right now the ShooterDemo example has a simulated recoil where the weapon shakes and the shots are simulated in a random cone spread. I was hoping to implement a recoil system similar to that of Counter-Strike where the gun slowly raises the users cursor up and they have to fight to keep it down.

What would the best approach to offsetting the user’s crosshair be? And should this replace any of the random spread logic where we just let the recoil of the cursor drive the spread of the shots?

Why would it replace any of the random spread logic? Technically if it were firing from the camera position then if the camera is pointing up the bullets should also be firing up WITH the random spread. That seems to make the most sense too me. :slight_smile:

Also what do you mean by the best approach? Are you talking about just the cross-hair? Or in reference to the cross-hair directing the player where the intended bullet is supposed to go?

The best place to start would likely be the UI for the cross-hairs if you wanted to go down that route, but I think your best interest would actually be to raise the camera itself and leave the cross-hairs alone. Basically the answer you want is going to be in ShooterCharacter.cpp.

If you’re still stuck just let me know. :slight_smile:

Ah sorry when I said the cross-hair should move up I was implying the camera pitch increasing not messing with the actual rendered cross-hair in the HUD.

To achieve the recoil seen in Counter-Strike is it as simple as just adding a little pitch offset? My guess is that if I was to just +5 to the pitch I’d see a very jerky recoil whereas in CS it is rather smooth. So I guess my new question is, how is the smooth pitch recoil in counter-strike achieved?

With gradual increments and not a constant. Quick increments and a slowed decrement.

This is one of the simplest things to implement. All CS does it increase the pitch of the camera, then it has a small time window when it pulls the camera back down again. The amount of kick increases for each consecutive shot.