help changing Player.viewPitch
Hey guys,
I am working on another mini-mod for muzzle climb, and I can't get the changes to the view to stick. When the gun shoots, the view rises for a frame (?) but then resets to where it was. For some reason the pitch addition is only temporary. This means that the actual viewPitch is being stored somewhere else. Does anyone know where the 'permanent' view angles are kept? Here's the code:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->//Rifle.pitchRecoil = 0.01
//in Rifle:FireBullet(player)
// add muzzle rise
local myAngles = player:GetViewAngles()
myAngles.pitch = myAngles.pitch + self.pitchRecoil
player:SetViewAngles(myAngles) //this only changes view for a frame
//player:SetAngles(myAngles) // another attempt; does nothing<!--c2--></div><!--ec2-->
I am working on another mini-mod for muzzle climb, and I can't get the changes to the view to stick. When the gun shoots, the view rises for a frame (?) but then resets to where it was. For some reason the pitch addition is only temporary. This means that the actual viewPitch is being stored somewhere else. Does anyone know where the 'permanent' view angles are kept? Here's the code:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->//Rifle.pitchRecoil = 0.01
//in Rifle:FireBullet(player)
// add muzzle rise
local myAngles = player:GetViewAngles()
myAngles.pitch = myAngles.pitch + self.pitchRecoil
player:SetViewAngles(myAngles) //this only changes view for a frame
//player:SetAngles(myAngles) // another attempt; does nothing<!--c2--></div><!--ec2-->
Comments
The variable myAngle is only valid in the scope of the function, it's value will be reset on the next call.
Edit: Ignore that, looks like that's intended. ;)
When the player fires, add to it like so:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->player.pitchRecoil = player.pitchRecoil + self.recoil_or_whatever<!--c2--></div><!--ec2-->
And in Player:OnProcessMove function, you will find a SetViewAngles call in there. Adjust the angles variable it uses like so:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local dt = Shared.GetTime()-self.lastOnProcessMove
player.pitchRecoil = player.pitchRecoil/(2*dt)
angles.pitch = angles.pitch+player.pitchRecoil
self.lastOnProcessMove = Shared.GetTime()<!--c2--></div><!--ec2-->
Tweak it until it suites your tastes.
Enjoy!