playMaker

Author Topic: Stop multiple weapons from firing at the same time  (Read 2227 times)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Stop multiple weapons from firing at the same time
« on: November 29, 2018, 02:51:38 PM »
I'm going bald from this, someone please help  ;D

I have three weapons, each starts firing by pressing x, y, z, so i'll call them like that, weapon x, weapon y and weapon z.

I made a neat little fsm for controlling weapons, so when i'm firing with x, let go of the button and press y, weapons switch and y starts firing.

However, to do that, i needed to put get key y, z to state where x is firing, get key, x, z when y is firing and get key x, y when z is firing so weapons can switch without the need for letting go of the buttons.

But the problem is that multiple weapons can fire simultaneously that way and i don't want that, i want only one weapon to fire at a time.

I can solve this by putting mid state in which you enter when you let go of the firing key x, y or z and the you press the button you want, but it's too slow and most of the player actually hit the button for firing the new weapon while they are still holding the button for firing the last one.
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Stop multiple weapons from firing at the same time
« Reply #1 on: November 30, 2018, 02:45:55 AM »
Here's the diagram to show you how it should work to make it easier.

Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Stop multiple weapons from firing at the same time
« Reply #2 on: November 30, 2018, 02:51:41 AM »
I have an idea of putting in variable "button pressed time" to alleviate the problem but i'm not quite sure how to implement it, hmm.
Available for Playmaker work

Athin

  • Full Member
  • ***
  • Posts: 163
Re: Stop multiple weapons from firing at the same time
« Reply #3 on: November 30, 2018, 02:54:25 AM »
What I'd do is set a simple FSM on each weapon. 

Basically each will sit at the listening stage waiting for their button to be push down.  When press, send it into a button up check(If they let go) and Bool check(checking if another gun is firing) that we'll call "Firing" each frame.  If firing is true nothing happens but if false, send an event to go into firing and setting the bool to true and listening for the button up.  Once they release the button, flip the bool.

Hope that helps as I had to write this pretty quickly.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Stop multiple weapons from firing at the same time
« Reply #4 on: November 30, 2018, 09:34:58 AM »
I get the vague notion of the idea, i'll give it a go.
Available for Playmaker work

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Stop multiple weapons from firing at the same time
« Reply #5 on: December 01, 2018, 06:26:10 AM »
Move the player input to a separate FSM, and instead of key down, use button down (you always want to use button down and only if going through the input manager is impractical, e.g. quick prototypes, temporary for debug or setup, web game with no key binding etc, go for key down).

How this works: There is just one state that listens for any possible button. When that button is pressed, it goes into a connected state that then sends off the event to the weapon, to fire it off. When that is done, perhaps after a very short wait action, it returns to the start state, listening to buttons again.

If you also need to know whether a different weapon was fired, for weapon switching, you could store the last button down, and compare it, and if false, add a contraption that does the proper switching.
« Last Edit: December 01, 2018, 07:08:37 AM by Thore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Stop multiple weapons from firing at the same time
« Reply #6 on: December 03, 2018, 01:06:13 AM »
Hi,

 another possibility is to properly implement a "active" "inactive" feature for each of your weapons, and when you enable one, the fsm knows it's enabled and will accept inputs. so in essence all weapons listen to input but they check if they are active before commiting.

 you can also have the fsm responsible for input watching on each weapon be disabled, that is also possible,

Bye,

 Jean

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Stop multiple weapons from firing at the same time
« Reply #7 on: March 23, 2019, 05:18:47 AM »
Hi guys, i solved the issue of multiple weapons firing together by simplifying the system and sending global event from input controller to weapons, but now i have issue of another nature.

When i press the button, FIRE event is sent to the designated weapon, when i release button STOP FIRING event is sent. That works fine for automatic weapons, but for manual weapons that are supposed to have some cooldown between shots, they can be overriden with continuous pressing of the fire button, thus resending the fire event again and again and overriding the cooldown.

Any ideas on how to overcome this?

Available for Playmaker work

Athin

  • Full Member
  • ***
  • Posts: 163
Re: Stop multiple weapons from firing at the same time
« Reply #8 on: March 23, 2019, 06:14:28 AM »
Hey there,

I'd just simple have a wait action with the delay you want.  When it enters this state, set a bool called Cooldown to true. Then the FSM listening for the button does a quick check on the bool first.  If its on Cooldown (Bool = True) then no event is sent, otherwise send.

Hope that helps.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Stop multiple weapons from firing at the same time
« Reply #9 on: March 23, 2019, 07:52:35 AM »
Hi guys, i solved the issue of multiple weapons firing together by simplifying the system and sending global event from input controller to weapons, but now i have issue of another nature.

When i press the button, FIRE event is sent to the designated weapon, when i release button STOP FIRING event is sent. That works fine for automatic weapons, but for manual weapons that are supposed to have some cooldown between shots, they can be overriden with continuous pressing of the fire button, thus resending the fire event again and again and overriding the cooldown.

Any ideas on how to overcome this?

Put the global event FIRE as a usual event under the state, then add a wait at the end, and then loop back to the state with FIRE underneath. That should do the trick. Though for autofire you need to add some more logic, I think, to keep the firing going.


Else, you need a separate state for the cooldown.
« Last Edit: March 23, 2019, 07:54:08 AM by Thore »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Stop multiple weapons from firing at the same time
« Reply #10 on: March 24, 2019, 12:03:28 AM »
Hi.
I recently work on a multiple weapon system.

What i did is :

have a fsm which handles buttons.
When a button is pressed, send an event to the desired weapon (for example weapon 1).
then do a next frame and go back to button listener.

if weapon 1 event is fired, i disable the other weapons with an event (not disabling the fsm itself)

when weapon 1 is done and other weapon are allowed to be used again, send an event again to the other weapons.

in my case i disable/enable a lot, so i also made a event handler fsm.

So from the weapon fsms i only need to send 1 event to the fsm handler.
and the handler will send the events to the other fsms.

which makes it a lot easier to handle.

Here is a image with a part of my event manager fsm.

« Last Edit: March 24, 2019, 12:05:25 AM by djaydino »