From e84e9ffe70c43f21942e09cd7e568c86cecb9c6c Mon Sep 17 00:00:00 2001 From: Stromic <38598074+Stromic@users.noreply.github.com> Date: Sun, 7 Aug 2022 22:53:32 +0200 Subject: [PATCH] Improved swimming Ability to jump out of water, swim smoothly --- .../controllers/PlayerWalkController.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/code/swb_base/obsolete/controllers/PlayerWalkController.cs b/code/swb_base/obsolete/controllers/PlayerWalkController.cs index 9c453e2a..fcb4bdb2 100644 --- a/code/swb_base/obsolete/controllers/PlayerWalkController.cs +++ b/code/swb_base/obsolete/controllers/PlayerWalkController.cs @@ -1,4 +1,4 @@ - + using Sandbox; /* Result from Pain Day 4, this will be here temporarily until it is clear how templates work */ @@ -155,7 +155,7 @@ public override void Simulate() // if ( underwater ) do underwater movement - if (AutoJump ? Input.Down(InputButton.Jump) : Input.Pressed(InputButton.Jump)) + if ((AutoJump || Swimming) ? Input.Down(InputButton.Jump) : Input.Pressed(InputButton.Jump)) { CheckJumpButton(); } @@ -436,7 +436,19 @@ public virtual void CheckJumpButton() // swimming, not jumping ClearGroundEntity(); - Velocity = Velocity.WithZ(100); + var jumpLedge = false; + + var startPos = Pawn.EyePosition; + + var tr = Trace.Ray( startPos, startPos + Pawn.EyeRotation.Forward * 1000 ) + .Ignore(Pawn) + .Run(); + + + if ( tr.Entity == null || tr.Entity.ClassName != "func_water" ) + jumpLedge = true; + + Velocity = Velocity.WithZ( jumpLedge ? 350 : 100 ); // play swimming sound // if ( player->m_flSwimSoundTime <= 0 )