Modifying mouse yaw/pitch?

AgielAgiel Join Date: 2006-11-14 Member: 58605Members, Constellation, NS2 Playtester, Subnautica Playtester
edited September 2010 in Modding
So, I've started playing around a bit with the code but ran into an obstacle when I wanted to implement recoil. Basically what I want to do is add some random yaw and pitch for each shot (I've already implemented free-aim which makes things a bit more complicated but I won't delve into that).

As far as I can tell the view angle is derived from input.yaw and input.pitch which are absolute values passed on from the engine. Simply changing them directly doesn't work since new values are sent each frame, so I'm guessing I'd either need a way to modify them in the engine or a way to get relative values instead. The latter would involve a lot of rewriting code but might be more flexible in the long run.

Now, either I missed something (very likely considering the current lack of documentation ;) or something like this just isn't possible yet. Anyone have any ideas/comments?

Comments

  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    modify the values in OverrideInput. the engine only calls OverrideInput on the client
  • AgielAgiel Join Date: 2006-11-14 Member: 58605Members, Constellation, NS2 Playtester, Subnautica Playtester
    How does that help? As I said, new values are sent each frame. Keeping some kind of offset might work for yaw but not for pitch since the value you get is clamped between -90 and 90 degrees.
  • AgielAgiel Join Date: 2006-11-14 Member: 58605Members, Constellation, NS2 Playtester, Subnautica Playtester
    Hey, I got back to coding after the latest patches and guess what i found :). Client.SetPitch and Client.SetYaw commands!

    If anyone wants to try NS2 with recoil just add this to ClipWeapon:FireBullets

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if (Client and (player == Client.GetLocalPlayer())) then
      if (viewAngles.pitch > math.pi) then
        Client.SetPitch(viewAngles.pitch - math.pi*2 - 0.01)
      else
        Client.SetPitch(viewAngles.pitch - 0.01)
      end
    end<!--c2--></div><!--ec2-->
    0.01 is the ammount of recoil in radians. Make that higher or lower if you want. Oh, and if you're playing with invert mouse make it + instead of -. I'm subtracting math.pi*2 since angles for objects always seem to be positive while mouse input should be between -pi/2 and pi/2.

    I don't know if anyone read this post or if they realized they needed the commands themselves, but thanks a lot! Now, finish up that shade so I can start playing around with the cloak shader ;)
Sign In or Register to comment.