### Preventing under water firing

Scripting questions, discussions, etc

#### Preventing under water firing

Duion
Posts: 673
Joined: Sun Feb 08, 2015 1:51 am

Currently I have a problem with the state machine of my weapons when going under water.
Normally it works fine, but I found a way to break out of the state machine which enables you to fire under water.

This is how I think it works:
When I enter water it enables the sprint animation so it looks like the player is swimming, this is done with:

stateName[4]                     = "ReadyMotion";   stateTransitionGeneric0In[4]     = "SprintEnter";   stateTransitionOnNoMotion[4]     = "Ready";   stateWaitForTimeout[4]           = false;   stateScaleAnimation[4]           = false;   stateScaleAnimationFP[4]         = false;   stateSequenceTransitionIn[4]     = true;   stateSequenceTransitionOut[4]    = true;   stateTransitionOnNoAmmo[4]       = "NoAmmo";   stateTransitionOnTriggerDown[4]  = "Fire";   stateSequence[4]                 = "run";

This is the state when the player is moving and you can see the state: "stateTransitionGeneric0In[4] = "SprintEnter";" which is probably what happens when entering water, so when entering water the player is sprinting and cannot fire the weapon or reload and all that stuff.

So now look at the sprinting state itself:
stateName[12]                    = "Sprinting";   stateTransitionGeneric0Out[12]   = "SprintExit";   stateWaitForTimeout[12]          = false;   stateScaleAnimation[12]          = false;   stateScaleAnimationFP[12]        = false;   stateSequenceTransitionIn[12]    = true;   stateSequenceTransitionOut[12]   = true;   stateAllowImageChange[12]        = false;   stateSequence[12]                = "sprint";

As you can see that the sprinting state has no case where it enters sprinting, so this is why when you manage to enter and dive under water while in the sprint state you will then exit the sprint state and end up back in the ready state, which enables you to fire under water, but as soon as you enter the water surface it will transition to swimming motion again.

So any ideas how to fix that?

#### Re: Preventing under water firing

Duion
Posts: 673
Joined: Sun Feb 08, 2015 1:51 am

So I did some more testing and it is definitely the sprint state.

If you fall into water it changes to sprint/swimming state, but if you fall and press shift for sprinting and then fall into the water the state machine will switch to sprintExit state which then switches to ready state which allows you to fire normally.

The problem is you cannot make stateTransitionGeneric0In = "Sprint" on the sprint state itself since you will never exit sprint state automatically then.

I also tried this resource: https://www.garagegames.com/community/f ... read/70121
Well it works to some degree, but in the end it just adds more ways it can go wrong than it solves. The check water state will only apply if you manage to sprint into water and skip the state machine to switch into swimming motion, so you will be under water in the ready motion, but on trying to fire it will just dry fire, so you can definitely not shoot underwater with that check, but you will be in the wrong state anyway.
It also may seem weird that sometimes in the water you are with swim animation and cannot shoot or dry fire and sometimes in ready state with dry fire.
The biggest problem with that resource was that if you exited water, the weapon will stay wet and you will be prevented from shooting even outside of water for indefinite time until you manually switch the weapon state into something else like sprinting etc.

#### Who is online

Users browsing this forum: No registered users and 1 guest