Jump to content

Preventing under water firing


Recommended Posts

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?

Link to comment
Share on other sites

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/forums/viewthread/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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...