Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: sachaMagne on April 12, 2013, 06:49:39 AM
-
Hi,
I would like to implement this behaviour with Playmaker but can't find the "proper playmaker" logic to do it:
I got a char. that got different states :running,walking and idle. I got the char. status through boolean and getting them is not a problem.
My issue is more a "playmaker logic" one:
I want to regenerate its energy after staying xx seconds in idle mode.
I tried actions timed based but ran into infinite loop at best...
I can't figure any functional and clean way to implement this basic system so far...
Any help would be appreciated !
Thanks
-
Here's the general idea; I'm assuming a new FSM just to keep this solution isolated from the rest of your unknown setup:
Below, I assume that you have access to that character-idle boolean, and I refer to it as "[char-idle]", whatever it is.
- State1: "Wait for Idle" (Start State) -- checks for [char-idle]==true every frame, and fires FINISHED once/if true. Transition: FINISHED --> "Reset Idle Time"
- State2: "Reset Idle Time" -- resets a float variable "IdleStartTime" to current time, and Transitions to "Charge" on FINISHED.
- State3: "Charge" -- (1) check bool [char-idle] EVERY FRAME and if FALSE, transition to "Wait for Idle" (if TRUE do nothing), (2) Check difference between "IdleStartTime" and current time EVERY FRAME; if >= X-seconds, transition to "Regenerate", else, do nothing. UPDATE: Fixed this by each of these checks happening every frame. Unless your [char-idle] is a global variable, may need to split this into 2 states, due to action limitations.
- State4: "Regenrate" -- Regenerate character's energy, and transition to "Wait for Idle"
This should do it, if implemented correctly.
Additional Note:
The reason you cannot use "Wait" anywhere in this solution, is because during that wait period, the character could leave and re-enter Idle mode and you would never know, giving the sneaky bastard a regen, when not deserved :)
-
Thanks for your explanation. It helps a lot. I found my first real problem was trying to do it in 3 states. I guess i should start thinking "atomic"...
thanks anyway, it works great.