playMaker

Author Topic: Using SendMessage effectively in Playmaker (from a Touch event)  (Read 5822 times)

Lonners

  • Playmaker Newbie
  • *
  • Posts: 4
Using SendMessage effectively in Playmaker (from a Touch event)
« on: November 01, 2011, 02:03:09 PM »
Hey guys.

I'm using a Touch GUI Event to send a message to a gameobject that then uses explosive force to push another particular game objects away from it.

So I'm using sendmessage to the script on the gameobject that expels the force - yet I can't seem to get it to work properly with the Sendmessage - because as soon as I touch the GUI object the message is only seemingly sent ONCE and not continuously - as I want the object to continue to expel the force.

What's the best way round this. Is send message the wrong way to go about it; I'm thinking it is and yet other solutions aren't presenting themselves to me as of yet...

Thanks
Lonners

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Using SendMessage effectively in Playmaker (from a Touch event)
« Reply #1 on: November 02, 2011, 07:41:32 AM »
Hi,

 The best way to go about it I think is to have two messages, one when the touch began, and one when it ended or was canceled somehow. Then you know when to start apply force, and when to stop without sending a message every update.

 Now, if you need the touch data to know from where to apply forces, then you can of course send a message every framed, or fill a fsm variable with information that you then use in your fsm that apply forces ( that fsm would only work when touched of course).

 Is that clear enough?

 Bye,

 Jean

Lonners

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Using SendMessage effectively in Playmaker (from a Touch event)
« Reply #2 on: November 10, 2011, 08:44:35 PM »
I've come back to this after sorting some other issues and I still can't really get it to work.

As it's Touch Gui event there's a whole load of Events available - thing is as soon as I use "Touch Begin" then we move onto the next state and so if on that same state there was "Touch Ended" then I can't use that transition for more than one thing?

Effectively all I need is a send message when the button is held down, and for it to stop when the button is released. I just can't seem to get the configuration correct for this using the states...it just constantly moves between states and I can't seem to get the same reaction as say just holding down a key...

I'm sure it should be simple but I just can't get it :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Using SendMessage effectively in Playmaker (from a Touch event)
« Reply #3 on: November 11, 2011, 04:51:10 AM »
Hi,

 you need to have one fsm responsible for handling touch begin and touch ended event, and that only.

 Start state watch for touch begin, then you transit to another state that dispatch a "button pressed event" . you can then go to another state that watch for touch ended or canceled, from that state you transit to a another state that will dispatch the event to whatever needs to know the touch as ended. From there go back to the start state to watch again for touch begin.

If you are using touch gui event, have one on both state, the first only dispatching Touch Began and the second dispatch the same event for Touch Ended and Touch Canceled.

I have attached an fsm that works, I tested it on the device and it runs fine. This is of course not a real world bullet proof fsm, because you would need need to handle touch id and when the touche is moved outside but not released, etc, but that's beyond the scope of this thread.

Bye,

 Jean


Lonners

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Using SendMessage effectively in Playmaker (from a Touch event)
« Reply #4 on: November 24, 2011, 04:33:58 PM »
I again got busy on many other things - this looks great I'll give it a try...although now Unity Remote is acting really slowly so I'll have to sort that first as it seems to lag too much :(

Thanks though :D

Lonners

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Using SendMessage effectively in Playmaker (from a Touch event)
« Reply #5 on: November 24, 2011, 04:55:01 PM »
Aha! I sorted the unity remote problem (bluetooth interference, doh!).

This works really well - except that I'm trying to send a constant message so that holding down the button should keep the function I'm sending a message to turned on. At the moment it just sends the message once, so I have to tappity tap to get the desired result.

Anyway a great tutorial in how to set up GUI on/off states, so thanks :D