News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Thread Tools Display Modes
Old 15th Oct 2010, 07:14 AM   #1
Registered User
Join Date: May. 27th, 2005
Posts: 701
Weapon Recoil like on Counter-Strike script?

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.
War_Master is offline   Reply With Quote
Old 15th Oct 2010, 08:23 AM   #2
Wormbo's Avatar
Join Date: Jun. 4th, 2001
Location: Germany
Posts: 5,786
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.)
Wormbo's UT/UT2004/UT3 mods | YouTube channel | PlanetJailbreak/JDN | Unreal Wiki | Liandri Archives
Everything you ever wanted to know about replication| UnrealScript security considerations
<elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
<TNSe> nono
<TNSe> its always funny to find code a week later you dont even remember writing
<Pfhoenix> what's worse is when you have a Star Wars moment
<Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"
Wormbo is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 05:44 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2015, vBulletin Solutions, Inc.

Copyright ©1998 - 2015, BeyondUnreal
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer