playMaker

Author Topic: Trying to Notify a running script from Playmaker  (Read 2554 times)

SeriousRPG

  • Playmaker Newbie
  • *
  • Posts: 45
Trying to Notify a running script from Playmaker
« on: October 28, 2013, 08:32:02 PM »
Hi;
I have just started implementing playmaker so this may seem like a dumb question.. I have an object (a bus) that has a script (patrol) attached. The bus follows a waypoint path. If the bus comes into a collision I want to pause the route and wait until the collision no longer exists, then resume.

In my patrol script, I can pause when I reach a destination but in this case, I want to interrupt it no matter where it is on the path between the waypoint1 and waypoint+1.

The following code is called in the script in the Update()
   //move towards the waypoint,
         //take the distance into consideration and limiter to how far the agent can move so it  wont overshoot it's destination
         Vector3 direction=(point-transform.position).normalized;
         transform.Translate(direction * Mathf.Min(dist, moveSpeed * Time.deltaTime), Space.World);
      
In the FSM I think I want to (1) detect collision (Collision Event), (2) set a variable. In script I want to test variable - if true do nothing, if false, do regular code.

How do I pass the variable and reference it from the script. Both the FSM and script are on the same object.

Thanks in Advance!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trying to Notify a running script from Playmaker
« Reply #1 on: October 29, 2013, 03:40:23 AM »
Hi,

 The quickest way is to fire a global event

Code: [Select]
using HutongGames.PlayMaker;
//..//
PlayMakerFSM.BroadcastEvent("MY EVENT");

To get the variable, the quickest way is to make that variable public, and use "Get property" action, simply drag and drop the script component onto the state action stack and you will be able to get / set it like so.


You can also fire a event to a specific fsm and fill event data, but that's more advanced, do you want to now? or the above will do?

Bye,

Jean


SeriousRPG

  • Playmaker Newbie
  • *
  • Posts: 45
Re: Trying to Notify a running script from Playmaker
« Reply #2 on: October 29, 2013, 08:45:31 PM »
Hi;
Not sure I understand the question. I have other vehicles patrolling around (with other instances of the patrol script on them), so if I broadcast, wouldn't all vehicles stop?

I want to trigger the event by colliding anything with my bus A, and doing so, pause my bus A until the object gets out of the way. I don't want to affect bus B or garbage truck C. (So I need to trigger from a specific FSM to pass the variable a specific script on the same object).

Also, I found I can't get Collision Event to work/fire but if I use Trigger Event I can. I don't want to specify a tag though because the bus can hit anything that gets in the way, not just certain objects.

As I said, I am a newbie so I may be explaining poorly....

Thanks,
Sandi

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trying to Notify a running script from Playmaker
« Reply #3 on: October 30, 2013, 02:26:45 AM »
Hi,

 then you need to send even to a specific gameobject. for this, I would recommand you get the PlayMakerUtils class from ArrayMaker, and I Build a convenient wrapper method to fire an event to a gameobject, it saves you from doing all the work.

The method is

Code: [Select]
PlayMakerUtils.SendEventToGameObject(thefsm,theGameObject,theEvent);

Tell me if that's clear enough,

bye,

 Jean

SeriousRPG

  • Playmaker Newbie
  • *
  • Posts: 45
Re: Trying to Notify a running script from Playmaker
« Reply #4 on: October 30, 2013, 08:33:11 PM »
I solved my issue, not sure if it was what you suggested.

I added two events in my FSM
On trigger Enter (collision): Send Event (Action=Send Message, CollisionOccurred)
On trigger Exit (collision): Send Event (Action=Send Message, CollisionCleared) and in the patrol script I added the two methods CollisionOccurred and CollisionCleared which manipulate a boolean, IsCollision. In the Update() I have IsCollision
- do nothing
else
- move

This works but I am not sure if it is terribly inefficient, or if it will cause other issues when there are more bus instances.

Is this method a dumb idea?

Thanks,
« Last Edit: October 30, 2013, 08:57:22 PM by SandiCassidy »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trying to Notify a running script from Playmaker
« Reply #5 on: October 31, 2013, 03:37:06 AM »
Hi,

 That's actually a very design pattern, much much better than for example sending a event everyframe, so you are definitly on the best path here.

bye,

 Jean