playMaker

Author Topic: Stop sending same Event  (Read 1428 times)

Mayhem

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Stop sending same Event
« on: October 29, 2013, 07:43:11 AM »
Hey there.

So I'm working on a 2D Game where you have to fight against enemies and I came up with a system which works fine for now. But I stumbled over an issue:
The Player has a little Lifesystem symbolised by three Hearts. If he got hit, one heart vanishes.
Let's say there are two enemies and when they both hit the Player at the exact same time the Player will loose not only 1 heart but 2 of them and this is the problem.

I made some screens so you can see it:


The black Box is the Player, the grey Box in the air is just a static Box which will send the "PlayerHit"-Event when an OnTriggerEvent occurs. This Event takes place on a FSM which is attached to the Player and executes the logic behind the Lifesystem.


As you see the black Boxs' Collider hits the Collider of the grey one, the Hit-Event is sent and the Player looses on of his hearts.


So, if i position another grey Cube, with the same height and same settings right next to the other one and let the Black Box fall the Player looses immediately two of his hearts.

Here are the FSMs of the grey Boxes:






I have an idea how to tackle this, but I don't know how I could do this with PlayMaker. I think the solution would be to check if the "PlayerHit" was sent already in that frame, if so, don't send it again.
What would be the PlayMaker-Approach?
Do you guys have better/easier ideas to tackle this?

Yanifska

  • Full Member
  • ***
  • Posts: 159
    • View Profile
    • My Portfolio
Re: Stop sending same Event
« Reply #1 on: October 29, 2013, 08:21:03 AM »
Maybe that before entering  the Hit state you can check if the HitCounter int is more than 0, if not it fires the event and update HitCounter by 1  so next time he won't enter again in that state? You will have to reset the int at some point then the question is when....
could that work ?
Visit my portfolio: http://www.yanivcahoua.com/

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3632
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Stop sending same Event
« Reply #2 on: October 29, 2013, 08:31:13 AM »
One way to do this in Playmaker is to use the Next Frame Event to return to State 1 instead of FINISHED. FINISHED triggers in the same update, so State 1 can get executed multiple times in a frame. Sometimes you want this, but in this case it seems like you only want it triggered once. You can use the Next Frame Event to return to State 1 in the next frame.

Alternatively, the FSM that receives the PlayerHit event can have multiple states. E.g., a simple Life Manager FSM might have Alive, Dying, and Dead states. The Dying and Dead states don't respond to PlayerHit events, so you don't lose extra lives.

The general "PlayMaker-Approach" is to break complex behaviours into simple states that carefully control what events to react to and what events to generate.