• Intensifying a viewpunch the longer the player has fired in a SWEP code
    4 replies, posted
So my current method that I'm using(which doesn't get the desired effect, but is sort of similar) is this: [code]self.Owner:ViewPunch( Angle( math.Rand( self:Clip1() / 8, -self:Clip1() / 8 ), math.Rand( self:Clip1() / 8, -self:Clip1() / 8 ) ,0 ) )[/code] But, what I want to do is intensify the viewpunch the longer the player has been firing(basically mimicking how HL2 weapons intensify the viewpunch the longer you've been firing). Yeah, I know the HL2 weapons are coded in C++, but mimicking it in Lua shouldn't be a problem(Fun fact: Supposedly in C++ weapon codes ViewPunch is an available command, and Garry just made viewpunch available for Gmod lua). I want to do this to encourage burst fire to make using the SWEP more challenging to handle.
[QUOTE=A Fghtr Pilot;47947326]So my current method that I'm using(which doesn't get the desired effect, but is sort of similar) is this: [code]self.Owner:ViewPunch( Angle( math.Rand( self:Clip1() / 8, -self:Clip1() / 8 ), math.Rand( self:Clip1() / 8, -self:Clip1() / 8 ) ,0 ) )[/code] But, what I want to do is intensify the viewpunch the longer the player has been firing(basically mimicking how HL2 weapons intensify the viewpunch the longer you've been firing). Yeah, I know the HL2 weapons are coded in C++, but mimicking it in Lua shouldn't be a problem(Fun fact: Supposedly in C++ weapon codes ViewPunch is an available command, and Garry just made viewpunch available for Gmod lua). I want to do this to encourage burst fire to make using the SWEP more challenging to handle.[/QUOTE] Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/KeyDown]Player:KeyDown[/url] with IN_ATTACK and just intensify it using a loop for how long it has been held down. It's kind of whacky but it's the only thing I can think of atm
I found a C++ function in the HL2 weapon codes that handles the recoil and intensifies it(I believe). If a C++ expert knows what they're doing here that could be done in Lua with different or similar functions, please let me know... [code]void CHL2MPMachineGun::DoMachineGunKick( CBasePlayer *pPlayer, float dampEasy, float maxVerticleKickAngle, float fireDurationTime, float slideLimitTime ) { #define KICK_MIN_X 0.2f //Degrees #define KICK_MIN_Y 0.2f //Degrees #define KICK_MIN_Z 0.1f //Degrees QAngle vecScratch; int iSeed = CBaseEntity::GetPredictionRandomSeed() & 255; //Find how far into our accuracy degradation we are float duration = ( fireDurationTime > slideLimitTime ) ? slideLimitTime : fireDurationTime; float kickPerc = duration / slideLimitTime; // do this to get a hard discontinuity, clear out anything under 10 degrees punch pPlayer->ViewPunchReset( 10 ); //Apply this to the view angles as well vecScratch.x = -( KICK_MIN_X + ( maxVerticleKickAngle * kickPerc ) ); vecScratch.y = -( KICK_MIN_Y + ( maxVerticleKickAngle * kickPerc ) ) / 3; vecScratch.z = KICK_MIN_Z + ( maxVerticleKickAngle * kickPerc ) / 8; RandomSeed( iSeed ); //Wibble left and right if ( RandomInt( -1, 1 ) >= 0 ) vecScratch.y *= -1; iSeed++; //Wobble up and down if ( RandomInt( -1, 1 ) >= 0 ) vecScratch.z *= -1; //Clip this to our desired min/max UTIL_ClipPunchAngleOffset( vecScratch, pPlayer->m_Local.m_vecPunchAngle, QAngle( 24.0f, 3.0f, 1.0f ) ); //Add it to the view punch // NOTE: 0.5 is just tuned to match the old effect before the punch became simulated pPlayer->ViewPunch( vecScratch * 0.5 ); }[/code] [editline]13th June 2015[/editline] [QUOTE=Flamingsword;47948207]Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/KeyDown]Player:KeyDown[/url] with IN_ATTACK and just intensify it using a loop for how long it has been held down. It's kind of whacky but it's the only thing I can think of atm[/QUOTE] What? :v: Funny x [b]1[/b] (list)
[code] function SWEP:Think( ) self.HeldDownTime = self.HeldDownTime or 0 self.LastThink = self.LastThink or CurTime( ) if self.Owner:IsValid( ) and self.Owner:KeyDown( IN_ATTACK ) and self:Clip1( ) > 0 then self.HeldDownTime = self.HeldDownTime + ( CurTime( ) - self.LastThink ) else self.HeldDownTime = 0 end self.LastThink = CurTime( ) end[/code] Something like that would probably work. Just scale your punching to the value of held down time.
-snip-
Sorry, you need to Log In to post a reply to this thread.