playMaker

Author Topic: Simulating a C# procedure with an FSM  (Read 223 times)

thierry_st_malo

  • Junior Playmaker
  • **
  • Posts: 55
    • View Profile
Simulating a C# procedure with an FSM
« on: January 11, 2018, 01:08:30 AM »
Hi, all!

I am working on a simple game about car driving.

For every wheel the same calculations are needed and my current approach is clumsy: there are four copies of the same FSM, changing the wheel collider for each.
It would be more efficient to have a single FSM launched four times during a single frame, just as in C# I would have a single procedure called four times.

What I should do, I guess, is this:

1. Launch the FSM for Wheel 1 and wait until it has completed its computations.
2. Do the same for Wheel 2.
3. Do the same for wheel 3, then for wheel 4.
4. Next Frame Event.
5. Restart the whole cycle.

But in Playmaker everything is asynchronous. So, how can I set up this organized sequence of events and actions?

Thanks in advance; I will be bery grateful for an answer.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2872
    • View Profile
    • jinxtergames
Re: Simulating a C# procedure with an FSM
« Reply #1 on: January 11, 2018, 01:37:30 AM »
Hi.
Can you show what actions you are using and are you on Playmaker 1.8.6?

The reason i ask what version is because Collider actions have been changed on 1.8.6 (you can now place them on a different object/fsm and select the collider gameobject )

thierry_st_malo

  • Junior Playmaker
  • **
  • Posts: 55
    • View Profile
Re: Simulating a C# procedure with an FSM
« Reply #2 on: January 12, 2018, 01:09:34 AM »
Hi,

I use Playmaker 1.8.6.f4 and the action "Get Wheel Collider Ground Hit Properties" that comes from the Ecosystem.

To be quite clear, let me re-phrase my problem: every frame, I must execute four identical and ordered action sequences before the update, and I wonder what is the best way to organize that. One FSM for all four Wheel colliders? Two FSMs? Four FSMs?

With C# I would create a function and call it four times.

Thanks for your help.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2872
    • View Profile
    • jinxtergames
Re: Simulating a C# procedure with an FSM
« Reply #3 on: January 12, 2018, 01:56:42 AM »
Hi.
I have not worked with wheel colliders yet,
But it kinda depends what you need to with the data

I think i would have an Fsm for each wheel (you can copy/paste the Fsm component or parameters )

Then if you need data from the wheel on another Fsm, use 'Set Fsm' actions.

I think it is better to have multiple smaller fsms than 1 large fsm.
Same as for scripts, i also tend to use Multiple smaller scripts.

thierry_st_malo

  • Junior Playmaker
  • **
  • Posts: 55
    • View Profile
Re: Simulating a C# procedure with an FSM [SOLVED]
« Reply #4 on: January 12, 2018, 03:24:23 AM »
Hi,

I quite agree with you, we want to avoid large FSMs. At this point, I think I'll try "Run FSM", which looks like what I'm going after. The description of the action is not very explicit, but there are more details in "Array For Each".

So, I'll try.

Thanks for your help.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3269
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Simulating a C# procedure with an FSM
« Reply #5 on: January 12, 2018, 08:51:12 PM »
Using Run FSM to run a Template FSM on each wheel is one way to go.

You can also use Array Get Next to loop through all wheels like in the attached screenshot. You would put the actions you want to run on each wheel in the Wheel Function state. Or you can run through more states before returning to Get Wheel.

Note, you can loop through many states in a single update. So, in this case, you can think of the FSM more like a flow chart, with each state describing a step in the process.



« Last Edit: January 12, 2018, 09:10:08 PM by Alex Chouls »