Gun sway and breathing for TTT

Hi all, just wondering if there is an addon out there that introduces player breathing so when they look through scopes they move, for example a sniper scope would sway, just like in call of duty.

Thanks

You could use some simple timers with some trig, with screen punches or calcview. Maybe a math clamp. Don’t know of any current addona though.

[editline]1st May 2016[/editline]

btw the formula to calculate the sway would be something like this (linear smoothing)



--note this is just some mock up code
--setup some variables
local transitionTime = 5   --how long it takes to smooth value
local currentTime = CurTime()
local endTime = currentTime + transitionTime
local timePassed = transitionTime - ( endTime - currentTime )
local startPosition = 10    -- start position
local endPosition = 50    --end position
local currentPosition = startPosition
-- after variables are setup call a function/hook or whatever

--inside some function/hook that loops
currentTime = CurTime()
if( ( endTime - currentTime ) >= 0) then
     timePassed  = transitionTime - ( endTime - currentTime )
     currentPosition = startPosition + ( ( endPosition * (timePassed) ) / ( math.pow( transitionTime, 2) ) )
end

--Basically if you want to go from 0 to 5 in 3 seconds the forumla is  0 + ( ( 5 * 3 ) / (3^2) ) = 5    ,   --divide by total transition time squared, and multiple the numerator by the current value of time that has passed


You coud adapt this idea to work with vectors or angles, then with a timer get a reasonable random time and a reasonable random vector, and fill in the forumla with the proper startPosition endPosition…etc.
Nonlinear smoothing would be a different formula but similar approach.

You could write a constructor function that would take in the data for random time and number/vector/angle. Then the function could initiate a hook that runs on calcview, inside the hook you can check if the transition time has passed and remove the hook.
I would transform those setup variables into a table and pass the function that table, those values would then be referenced inside the hook, you could even change the startPosition and endPosition on-the-fly, point is you wont need to call the function that initializes the hook everytime you need a sway.

yo thanks man, but I only know basic LUA so this looks so hard for me to do :frowning:

Cheers anyways though!

Thats actually most of the code, I’m a bit busy right now…but later on ill wrap that up into a function for you and show you how to call the function from



PLAYER:ViewModelChanged( Entity viewmodel, string old, string new ) 
--This hook gets called when you change weapons, although to detect if a player is aiming I think the proper way would be to change some code in the weapon entity file. You could do a tacky solution by using this hook and detecting if the player has mouse2 pressed though


Ill upload another post later today.

[editline]1st May 2016[/editline]

Alos, I guess you could just implement a small sway for all weapons besides build tools, this would get magnified if a weapon zooms in to aim and such.