Permalink
Browse files

Added HL2 jumping system back to Sandbox (now works in multiplayer as…

… well)
  • Loading branch information...
1 parent 4bcdef6 commit e7befa2e8cdd68dbb9185615506eda96e8620f76 @UnderscoreKilburn UnderscoreKilburn committed Mar 28, 2014
Showing with 49 additions and 5 deletions.
  1. +49 −5 garrysmod/gamemodes/sandbox/gamemode/player_class/player_sandbox.lua
@@ -139,13 +139,57 @@ function PLAYER:CalcView( view )
end
-function PLAYER:GetHandsModel()
-
- -- return { model = "models/weapons/c_arms_cstrike.mdl", skin = 1, body = "0100000" }
+--
+-- Reproduces the jump boost from HL2 singleplayer
+--
+local JUMPING
- local cl_playermodel = self.Player:GetInfo( "cl_playermodel" )
- return player_manager.TranslatePlayerHands( cl_playermodel )
+function PLAYER:StartMove( move )
+
+ -- Only apply the jump boost in FinishMove if the player has jumped during this frame
+ -- Using a global variable is safe here because nothing else happens between SetupMove and FinishMove
+ if bit.band( move:GetButtons(), IN_JUMP ) ~= 0 and bit.band( move:GetOldButtons(), IN_JUMP ) == 0 and self.Player:OnGround() then
+ JUMPING = true
+ end
+
+end
+function PLAYER:FinishMove( move )
+
+ -- If the player has jumped this frame
+ if JUMPING then
+ -- Get their orientation
+ local forward = self.Player:EyeAngles()
+ forward.p = 0
+ forward = forward:Forward()
+
+ -- Compute the speed boost
+
+ -- HL2 normally provides a much weaker jump boost when sprinting
+ -- For some reason this never applied to GMod, so we won't perform
+ -- this check here to preserve the "authentic" feeling
+ local speedBoostPerc = ( ( not self.Player:Crouching() ) and 0.5 ) or 0.1
+
+ local speedAddition = math.abs( move:GetForwardSpeed() * speedBoostPerc )
+ local maxSpeed = move:GetMaxSpeed() * ( 1 + speedBoostPerc )
+ local newSpeed = speedAddition + move:GetVelocity():Length2D()
+
+ -- Clamp it to make sure they can't bunnyhop to ludicrous speed
+ if newSpeed > maxSpeed then
+ speedAddition = speedAddition - (newSpeed - maxSpeed)
+ end
+
+ -- Reverse it if the player is running backwards
+ if move:GetForwardSpeed() < 0 then
+ speedAddition = -speedAddition
+ end
+
+ -- Apply the speed boost
+ move:SetVelocity(forward * speedAddition + move:GetVelocity())
+ end
+
+ JUMPING = nil
+
end
player_manager.RegisterClass( "player_sandbox", PLAYER, "player_default" )

0 comments on commit e7befa2

Please sign in to comment.