playMaker

Author Topic: Rapid fire from a projectile weapon  (Read 1545 times)

Karin

  • Playmaker Newbie
  • *
  • Posts: 18
Rapid fire from a projectile weapon
« on: August 05, 2020, 05:57:18 AM »
Hello

I've been trying to figure out the best possible way for an FSM to repeat a function loop upon creating a projectile. The issue is on get key down and key up, they don't seem to read if the new event tries to detect button presses consistently.

I would be interested to know how others would approach this.

nuFF3

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 74
  • Are we even real?
    • One Month Studio
Re: Rapid fire from a projectile weapon
« Reply #1 on: August 05, 2020, 08:18:42 AM »
Use a "key down", or equivalent, in the first state, use a "wait" action in the next state. Set the wait timer to something small like 0.1
Have the states be connected together, and hey presto! A simple repeating loop as long as the button is pressed.

Karin

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Rapid fire from a projectile weapon
« Reply #2 on: August 05, 2020, 10:04:33 AM »
Use a "key down", or equivalent, in the first state, use a "wait" action in the next state. Set the wait timer to something small like 0.1
Have the states be connected together, and hey presto! A simple repeating loop as long as the button is pressed.

As I mentioned in my post I did exactly that. It does not loop. I tested it with a debug log feed just to be sure of it.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rapid fire from a projectile weapon
« Reply #3 on: August 05, 2020, 10:05:40 AM »
Hi.
You could separate the fsm key part to enable disable the projectile shooting.

(Best solution but might take a little more time to set up)
FSM 1 :
State 1
Get Key Down (transition to state 2)
Send Event (By Name) send 'Disable' Event

State 2
Get Key Up (transition to state 1)
Send Event (By Name) send 'Enable' Event

Fsm 2 :
Have a empty state and place a global event (Disable)
Then have a Global Event Connected to your projectile States.


Or you could use a 'Get Key' and get the bool Status, then do a bool test on that value.
(fastest solution)

Karin

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Rapid fire from a projectile weapon
« Reply #4 on: August 05, 2020, 10:18:32 AM »
Hi.
You could separate the fsm key part to enable disable the projectile shooting.

(Best solution but might take a little more time to set up)
FSM 1 :
State 1
Get Key Down (transition to state 2)
Send Event (By Name) send 'Disable' Event

State 2
Get Key Up (transition to state 1)
Send Event (By Name) send 'Enable' Event

Fsm 2 :
Have a empty state and place a global event (Disable)
Then have a Global Event Connected to your projectile States.


Or you could use a 'Get Key' and get the bool Status, then do a bool test on that value.
(fastest solution)


That's a very interesting approach, thanks I'll get back to you on the result.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rapid fire from a projectile weapon
« Reply #5 on: August 05, 2020, 10:33:51 AM »
Hi.
Key Down will be registered once by a action.
If its still holding down when looping back, it won't see this as a pressing down. as key has not been released since.
And in scripting it works the same ways, as in many other cases you would not want to loop, until pressed again.

Karin

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Rapid fire from a projectile weapon
« Reply #6 on: August 05, 2020, 10:45:24 AM »
Hi.
Key Down will be registered once by a action.
If its still holding down when looping back, it won't see this as a pressing down. as key has not been released since.
And in scripting it works the same ways, as in many other cases you would not want to loop, until pressed again.

My thoughts exactly, because it's not the same as Key hold. I don't think Playmaker has this function, is it possible to make this as a custom action?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rapid fire from a projectile weapon
« Reply #7 on: August 05, 2020, 10:56:25 AM »
Hi.
'Get key' + 'Bool Test' is doing this.
Make sure to Enable Every Frame.

Karin

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Rapid fire from a projectile weapon
« Reply #8 on: August 05, 2020, 11:06:49 AM »
Are we talking every frame for both Get key and Bool test?
Regardless of the combination I get 1000 reach crash, i must be doing something wrong. I may have to show pics of what it is I'm trying to achieve.

For a moment i was under the impression key was another version of key down. I had no idea it had every frame.
« Last Edit: August 05, 2020, 11:14:15 AM by Karin »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rapid fire from a projectile weapon
« Reply #9 on: August 05, 2020, 11:16:08 AM »
Hi.
Yes as it should get the value every frame and also check the result every frame.

Else it will only Get/Test once.

Karin

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Rapid fire from a projectile weapon
« Reply #10 on: August 05, 2020, 11:33:38 AM »
This requires a third state, because it's going WAY too fast!
This allows the conditions you mentioned to breath, because it's going at a speed that the FSM can't deal with.

Thanks once again this very helpful.  :D

Out of curiosity does FSM state switch, work on a global status?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rapid fire from a projectile weapon
« Reply #11 on: August 05, 2020, 02:07:52 PM »
Hi.
Set a wait in between the loop to have a delay for this case as you probably want a certain time between each shot.

In other cases there is also a 'Next Frame Event'

Quote
Out of curiosity does FSM state switch, work on a global status?

To check the state on another, yes.
The send event on the action is local.