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

  • 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.

War_Master

Member
May 27, 2005
702
0
16
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.
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
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:
Code:
var float RecoilLeft;

function ApplyRecoil(int Amount)
{
  ApplyRecoilToPlayer(Amount);
  RecoilLeft += Amount;
}

function Tick(float DeltaTime)
{
  local float RecoilToRemove;
  local int ActualRecoil;

  RecoilToRemove = FMin(DeltaTime * RecoilLeft, 0);
  if (RecoilToRemove == 0)
    return;

  ApplyRecoilToPlayer(-RecoilToRemove);
  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.)