1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

UE1 - UT Weapon Recoil like on Counter-Strike script?

Discussion in 'Programming' started by War_Master, Oct 15, 2010.

  1. War_Master

    War_Master Member

    May 27, 2005
    Likes Received:
    Ive been working on a weapon and want to add recoil to it. The script I have for the recoil just makes the camera move upwards and I have to move the mouse down endlessly in order to return it to the proper position. What I'm looking for is a way to make the camera go back down to the position where the recoil started to happen just like it does on the Counter-Strike game. Is there a known script for U1 engine that does that already? Or, is this even possible in this engine? And if so, could you please help figure this out by showing a script that would work?

    I would really appreciate any help since this is something new to me because Ive never seen it done on any mod.
  2. Wormbo

    Wormbo Administrator Staff Member

    Jun 4, 2001
    Likes Received:
    For the recoil you probably add a certain amount of Pitch to the player's view rotation. How about removing that amount again, but spread across the ticks of, say, the next second.

    For example:
    var float RecoilLeft;
    function ApplyRecoil(int Amount)
      RecoilLeft += Amount;
    function Tick(float DeltaTime)
      local float RecoilToRemove;
      local int ActualRecoil;
      RecoilToRemove = FMin(DeltaTime * RecoilLeft, 0);
      if (RecoilToRemove == 0)
      RecoilLeft -= RecoilToRemove;
    This might need some tweaking to account for Pitch being an int value. Also you might want to experiment with non-linear falloff functions. UT3's FInterpTo is a good example for this kind of function. I think it implements exponential falloff. (Unfortunately it's implemented in native code, so I don't know how it calculates the falloff.)

Share This Page