playMaker

Author Topic: How to: FSM to FSM Communication  (Read 1651 times)

Thore

  • Sr. Member
  • ****
  • Posts: 480
How to: FSM to FSM Communication
« on: October 02, 2017, 05:23:37 PM »
Hi,

Despite that I have built quite a lot of mechanics with Playmaker already, I still feel unsure about the FSM to FSM commuication, which is an increasingly common challenge.

For example, creating a new object and passing variables to it. What's the best way to go about it? Are Send Events always fast enough to ensure the variables are set in Start state? Or should you create the object, have Start run empty (or only do configuration that are self-contained), set variables, and then trigger a global event to really set it into motion?

Another example: When a projectile hits a target: what's the best way to do this? Is it better for the Health FSM to be hit, then get projectile information, or is it better that the projectile hits an object, and passes its variables onto the object? Or some combination thereof?

Are there any good tricks that make communication between FSMs less complicated? A rule of thumb or something of the sort?

I also ask because I've seen many different tutorials and even more ways how this can be done, but none stick out as clearly superior. Any pointers, and reasons?


Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to: FSM to FSM Communication
« Reply #1 on: October 02, 2017, 06:00:13 PM »
Depends how do you want it to work and how scalable it needs to be. I have projectiles that deal normal/double/half damage depending on the type of enemy they hit, so i put all the logic in the projectile and pass the stuff to the object. It stores the collider in a variable and then manipulates the variable of the object hit (reduce hp/destroy) before despawning itself. Of course, it all occurs over two frames so it's basically at the same time to the human eye.
Available for Playmaker work

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How to: FSM to FSM Communication
« Reply #2 on: October 02, 2017, 06:41:21 PM »
Depends how do you want it to work and how scalable it needs to be. I have projectiles that deal normal/double/half damage depending on the type of enemy they hit, so i put all the logic in the projectile and pass the stuff to the object. It stores the collider in a variable and then manipulates the variable of the object hit (reduce hp/destroy) before despawning itself. Of course, it all occurs over two frames so it's basically at the same time to the human eye.

I have modular system, with is a game object with a FSM "Health", which waits for a global event. A projectile, on hit, will look for the Health FSM game object, then send over the damage, and right afterwards set off the global event in the Health FSM, which starts it.

Within that, it copies over the damage from the incoming variable, and empties the incoming bin. The damage (or energy, because I also use it for healing, damage is minus, heal is plus) is then computed in the fsm, substrat from current HP, and if below zero triggers the Death. It works neatly, so far, but I still look for something more than "it works".

Even more detail, see here.

I wonder if there are objectively some best practices on the general problem of FSM/FSM communication.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to: FSM to FSM Communication
« Reply #3 on: October 03, 2017, 02:49:31 AM »
That's a good solution, i don't see how it can be improved or shortened.
Available for Playmaker work