playMaker

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

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 988
    • View Profile
    • Fat Pug Studio
Stop multiple weapons from firing at the same time
« on: November 29, 2018, 12: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.

krmko

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


krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 988
    • View Profile
    • Fat Pug Studio
Re: Stop multiple weapons from firing at the same time
« Reply #2 on: November 30, 2018, 12: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.

Athin

  • Junior Playmaker
  • **
  • Posts: 98
    • View Profile
Re: Stop multiple weapons from firing at the same time
« Reply #3 on: November 30, 2018, 12: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.

krmko

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

Thore

  • Sr. Member
  • ****
  • Posts: 265
    • View Profile
Re: Stop multiple weapons from firing at the same time
« Reply #5 on: December 01, 2018, 04: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, 05:08:37 AM by Thore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14244
  • Official Playmaker Support
    • View Profile
Re: Stop multiple weapons from firing at the same time
« Reply #6 on: December 02, 2018, 11:06:13 PM »
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

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 988
    • View Profile
    • Fat Pug Studio
Re: Stop multiple weapons from firing at the same time
« Reply #7 on: March 23, 2019, 02: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?


Athin

  • Junior Playmaker
  • **
  • Posts: 98
    • View Profile
Re: Stop multiple weapons from firing at the same time
« Reply #8 on: March 23, 2019, 03: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: 265
    • View Profile
Re: Stop multiple weapons from firing at the same time
« Reply #9 on: March 23, 2019, 04: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, 04:54:08 AM by Thore »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4323
    • View Profile
    • jinxtergames
Re: Stop multiple weapons from firing at the same time
« Reply #10 on: March 23, 2019, 09:03:28 PM »
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 23, 2019, 09:05:25 PM by djaydino »
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions