Press crouch to move down while in the water

Thu Feb 10, 2022 2:41 am

By default, the player just crouches even while in the water when the player presses the crouch key.
It's kinda odd for me, so I'd like to make the player moving down to the bottom while pressing the crouch key like Blood (in short, inverse of the jump key - in the water, he's moving up when presses the jump key).

I think that's possible to change from the player.zs, however it's really delicate.

Here is the code:
Spoiler:


I added 2 things from the original;
This,
Code:
      if (player.cmd.buttons & BT_CROUCH && waterlevel >= 1)
      {
          Vel.Z = -4 * Speed;
      }


And waterlevel == 0 of this.
Code:
if (!totallyfrozen && waterlevel == 0)


I don't know what's happened though, it seems player.cmd.buttons & BT_CROUCH is not worked.
Moreover, the jump key won't work underwater soon when pressing the both crouch key and jump key repeatedly. Yes, I gave up on solving it only by myself.

I hope there is a solution to this, but is it impossible to modify this without getting into a maze of the source code?


Thanks in advance!

Re: Press crouch to move down while in the water

Thu Feb 10, 2022 10:53 am

It would be nice to have this functionality not only when underwater. I'm using the zscript ladders, which makes player fly, so it could be fine to have this also for flying. And that could be little bit trickier in zscript.

Mentioned ladder system could be found here: viewtopic.php?f=3&t=55951&p=990558&hilit=Zscript+ladder#p990558

Re: Press crouch to move down while in the water

Thu Feb 10, 2022 10:23 pm

Use this code in your player class:
Code:
   static const int flyspeed[] = { 1 * 256, 3 * 256 };

   override void CheckCrouch(bool totallyfrozen)
   {
      let player = self.player;
      UserCmd cmd = player.cmd;

      if (cmd.buttons & BT_CROUCH) { cmd.upmove -= flyspeed[!!(cmd.buttons & BT_SPEED ^ cl_run)]; }

      Super.CheckCrouch(totallyfrozen);
   }


The speed values are taken from g_game.cpp.

Re: Press crouch to move down while in the water

Thu Feb 10, 2022 11:56 pm

AFADoomer wrote:Use this code in your player class:
Code:
   static const int flyspeed[] = { 1 * 256, 3 * 256 };

   override void CheckCrouch(bool totallyfrozen)
   {
      let player = self.player;
      UserCmd cmd = player.cmd;

      if (cmd.buttons & BT_CROUCH) { cmd.upmove -= flyspeed[!!(cmd.buttons & BT_SPEED ^ cl_run)]; }

      Super.CheckCrouch(totallyfrozen);
   }


The speed values are taken from g_game.cpp.


It doesn't work for me.The player can still crouch underwater(or even while flying). Or, should I add something based on the AFADoomer's code?

Re: Press crouch to move down while in the water

Fri Feb 11, 2022 3:15 am

Laskow wrote:The player can still crouch underwater(or even while flying).

Just a concern: if you disable crouching while swimming/flying, what happens when you play a map with a low tunnel (etc) that you need to crouch to swim or fly through?

Re: Press crouch to move down while in the water

Fri Feb 11, 2022 3:50 am

Enjay wrote:Just a concern: if you disable crouching while swimming/flying, what happens when you play a map with a low tunnel (etc) that you need to crouch to swim or fly through?


I'd like to make this mechanism for my total conversion, so just I don't make a map which need to crouch in the water. That's the only way.

Re: Press crouch to move down while in the water

Sat Feb 12, 2022 3:16 am

Code:
   static const int flyspeed[] = { 1 * 256, 3 * 256 };

   override void CheckCrouch(bool totallyfrozen)
   {
      let player = self.player;
      UserCmd cmd = player.cmd;

      if (cmd.buttons & BT_CROUCH)
      {
         cmd.upmove -= flyspeed[!!(cmd.buttons & BT_SPEED ^ cl_run)];
      }

      if (waterlevel != 0) //Prevent crouching underwater
      {
         player.crouching = 1;
         CrouchMove(1);
         player.Uncrouch();
      }

      Super.CheckCrouch(totallyfrozen);
   }

Okay, I found a way to prevent crouching underwater using the AFAdoomer's code.
Still there is one problem. It's truly difficult to make the player moving down with the crouch key while underwater than I imagined!
It seems checking crouching is not as simple as checking jumping.

[EDIT]
Oh gosh, sorry. It was a misunderstanding.
The AFADoomer's code only works when you use the "crouch" key, not ‚Äčthe "crouch toggle". I've set the CTRL key as the "crouch toggle" and that's why it didn't work well.

It would be nice if it also works for "crouch toggle" though, this is what I wanted for a long time.
Thanks a lot!!


By the way, replace "waterlevel != 0" with something like "FindInventory("yourinventorynamehere")" from the above code, if you want to prevent crouching while climbing a ladder and check whether climbing or not by using the inventory item.

Re: Press crouch to move down while in the water

Sat Feb 12, 2022 6:12 pm

Ah. Sorry, I forget that people actually use that bind... I've never understood why (other than that it somehow snuck in as the default in GZDoom).

Re: Press crouch to move down while in the water

Sat Feb 12, 2022 7:14 pm

AFADoomer wrote:Ah. Sorry, I forget that people actually use that bind... I've never understood why (other than that it somehow snuck in as the default in GZDoom).

I much prefer crouch toggle to just crouch. Why? If I press crouch I have to keep my finger on the crouch button while sneaking around. If I press crouch toggle, I can press it and then concentrate on my other button-pushes. :)