help changing Player.viewPitch

HakujinHakujin Join Date: 2003-05-09 Member: 16157Members, Constellation
edited April 2010 in Modding
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-->

Comments

  • Raza.Raza. Join Date: 2004-01-24 Member: 25663Members, Constellation
    edited April 2010
    Without really thinking about it:
    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. ;)
  • DecoDeco Join Date: 2010-04-10 Member: 71288Members, WC 2013 - Shadow
    Make sure pitchRecoil isn't being reset instantly.

    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!
Sign In or Register to comment.