Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Razieln64 on June 23, 2011, 02:07:35 PM

Title: Adding a delay before an action
Post by: Razieln64 on June 23, 2011, 02:07:35 PM
I'm coding a custom action tailored to my game. My problem is that when entering a state, my FSM has to wait a certain amount of time before doing this custom action. At the same time the state is playing an animation that will generate an event getting the FSM to a new state.

I've tried using a coroutine but unfortunately it doesn't work in an FSM. My custom action works fine but it can only be triggered at the beginning of the state. Is it possible to implement a delay before this action? Do I need to split the animation and the state in 2 to get it working? Is there a simple solution to that because coding seems easier in this situation. Thanks
Title: Re: Adding a delay before an action
Post by: tofusoup on June 23, 2011, 04:29:20 PM
Not sure I get 100% of what's going on but there is a Send Event Actin with Delay option.

I find it always easier to break up what you want to do into smaller FSM that just Gets or Sets values where you need it.

dunno if this is useful heh.  Hopefully someone else chimes in

Title: Re: Adding a delay before an action
Post by: justifun on June 23, 2011, 04:44:46 PM
Yeah you can split it into 2 states to get it to work.  have the first state an action of "wait" for however many seconds you want it to stall for (eg: the length of your original animation), and then send it to the next state afterwards.

thus a pause while it waits for your previous state animation to finish playing
Title: Re: Adding a delay before an action
Post by: Alex Chouls on June 23, 2011, 04:58:16 PM
I would also suggest splitting this into 2 states, but if you really need to stay in 1 state, your custom action can read how long the current state has been active using State.StateTime (see GetTimeInfo.cs for an example). You could test against this to add a delay to your action.
Title: Re: Adding a delay before an action
Post by: LordShaggy on June 23, 2011, 05:49:40 PM
Yea, I've used it before for something like that. What alex said works pretty well.
Title: Re: Adding a delay before an action
Post by: justifun on June 23, 2011, 10:33:45 PM
Hey alex, is there a way to ask how long an animation clip is?
Title: Re: Adding a delay before an action
Post by: Razieln64 on June 25, 2011, 07:52:44 PM
Thanks. I've figured it out. I just called an external coroutine that does my delayed action. It's outside the FSM but it works fine. I then set some variables of the FSM using the external coroutine and it works! Unfortunately I can't use the delayed event  because this would generate an event that takes the FSM to another state but it's the animation started in the actual state that determines the state change. So it's like I'd have 2 states at the same time which is not possible...