Different projectiles depending on the player's movement (zscript)

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
OddYokai
Posts: 13
Joined: Mon Jul 04, 2022 11:01 am
Preferred Pronouns: He/Him
Graphics Processor: ATI/AMD (Modern GZDoom)
Location: Hungary

Different projectiles depending on the player's movement (zscript)

Post by OddYokai »

Hello!
How could I make the weapon take into account the player's movement? I want to make the weapon fire a different projectile when the player moves forward than when moving backwards?

Maybe is it possible to make the weapon also detect that the player jumps or is in the air?
User avatar
OddYokai
Posts: 13
Joined: Mon Jul 04, 2022 11:01 am
Preferred Pronouns: He/Him
Graphics Processor: ATI/AMD (Modern GZDoom)
Location: Hungary

Re: Different projectiles depending on the player's movement (zscript)

Post by OddYokai »

OK, I figured out part of the problem on my own.

I just put this in the moment before the shot:

Code: Select all

TNT1 A 0 A_JumpIf(GetPlayerInput(INPUT_BUTTONS) & BT_FORWARD, "ALT1");
TNT1 A 0 A_JumpIf(GetPlayerInput(INPUT_BUTTONS) & BT_BACK, "ALT2");
Now I just want to know how to check if the player is in the air. (whether it actually jumps is irrelevant). If the player is in the air, then the code jumps to the state "ALT3";
Last edited by OddYokai on Sat Feb 03, 2024 9:50 am, edited 1 time in total.
Jarewill
 
 
Posts: 1845
Joined: Sun Jul 21, 2019 8:54 am

Re: Different projectiles depending on the player's movement (zscript)

Post by Jarewill »

It will be better to check for the player's forwardmove instead, as it takes controllers into consideration:

Code: Select all

TNT1 A 0 A_JumpIf(player.cmd.forwardmove > 0, "ALT1");
TNT1 A 0 A_JumpIf(player.cmd.forwardmove < 0, "ALT2");
As for checking if the player is in the air, you can either compare the player's Z position to the floor (pos.z <= floorz) or check the player's onground property. (player.onground)
User avatar
OddYokai
Posts: 13
Joined: Mon Jul 04, 2022 11:01 am
Preferred Pronouns: He/Him
Graphics Processor: ATI/AMD (Modern GZDoom)
Location: Hungary

Re: Different projectiles depending on the player's movement (zscript)

Post by OddYokai »

it works great, thank you!

But I have another question that is only loosely related to the topic (I hope it's not a problem). with this method, I can also make the weapon jump to the "walking animation" state while the player is moving, am I right? or is there a more efficient solution?
Jarewill
 
 
Posts: 1845
Joined: Sun Jul 21, 2019 8:54 am

Re: Different projectiles depending on the player's movement (zscript)

Post by Jarewill »

Yes that should work.
You could also use vel.xy.length(), but that would trigger even if the player has horizontal velocity applied in any other way.

Return to “Scripting”