playMaker

Author Topic: Send an event to another object?  (Read 3206 times)

PET

  • Full Member
  • ***
  • Posts: 139
    • GamerPET
Send an event to another object?
« on: August 26, 2015, 12:30:09 PM »
Hello guys,

there are a couple of things that I'm trying to do.

I have 3 States...

Welcome State
Scale Time = 0
Get Key Down = Return

Basically when the game starts I pause the whole game, I display an UI Text and I wait for the "Return Key".

Run Game
Activate Game Object (I deactivate the UI Text)
Scale Time = 1
Get Key Down = Return (For testing purposed, when pressed I send the last event)

End Game
This event will trigger when my object will reach the end of the level. I will do it with a trigger. Currently this event is activated by pressing Return when in "Run Game" state. Also currently this event is doing a RESTART LEVEL and it sends the machine back to the "Welcome State".

http://puu.sh/jPmbW/5756b8f03c.png

What I want to do is... when I'm in "Run Game" state I want to sent an event to my car wheels.

This is the FSM of the Car Wheels:
http://puu.sh/jPmd7/51f27c7062.png

Basically I want them to wait for that Event that is being sent by the "Run Game"... and when that event is received I want to go into the second state "Wheel Rotation" and basically "animate" my wheels. it's just an X Rotation.

Questions:

1. How can I sent an event from one FSM to the other. I'm doing something like this:
http://puu.sh/jPmhp/5b876990e7.png
Main problem is that I don't know how to make the Wheels to "LISTEN" for that startWheelRotation event. How do I do this? All tutorials are doing something similar with "Trigger Event" but that requires a rigidbody and it dosn't really apply to me.

So how to do it?


2. Am I doing the restart procedure of my level correctly? I'm building a demo basically and I want to be able to restart the whole game when my car reaches the end of the level.

Thank You


Technical Game Designer
www.GamerPET.com

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: Send an event to another object?
« Reply #1 on: August 26, 2015, 01:45:51 PM »
On the car wheels GameObject, make the event global (click the checkbox next to it).

On the run game state you add a Send Event action, but set it to Game Object FSM, specify GameObject, and add the car wheels, along with the FSM and the event.

To restart the scene you can use the Restart Level action.

PET

  • Full Member
  • ***
  • Posts: 139
    • GamerPET
Re: Send an event to another object?
« Reply #2 on: August 26, 2015, 02:10:07 PM »
Thanks. I was thinking on doing it like this but the Specify Game Object... I have 4 wheels since the wheel is not a prefab. But thinking about it... all I have ot do is just sent 4 events to each wheel in particular. I did a test with "Broadcast All" and it works.

I did a Global Event called "startWheelRotation" but I did that in my main State Machine and not on the wheels.

But it makes sense now. The event from the wheels has to be started by something.

Thinking about it, does it matter where I set up the Event considering that it's Global?

My "Restart level" action behaves very strange. It seems that every time I restart the level I get a "time" value randomly and my objects are kind of never on the same spot. The car is a bit forward then a bit back... then forward again... our programmer will look into it. It might be a Unity bug.

Thanks for explaining. Events make more sense now. Event is something that... HAPPENS. When an Event happens it will go into the State it was setup to go. It doesn't matter where that Event happens... it can be sent from other States, other FSM and even a trigger.

Basically that's what a trigger does... it SENDS and event when somethign enter/exits/etc from him.

right?
Technical Game Designer
www.GamerPET.com

Grendal

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Send an event to another object?
« Reply #3 on: August 27, 2015, 10:41:49 PM »
Yes, events are nameable calls telling Playmaker to go to another state via a transition (themselves).
You could make an event for "Baloney Sandwich" and send it when ham sandwich action bool compare equals true... Playmaker is not bad at sandwich, it just don't care.

The important thing is whether its a local or global event. Setting events as global allows you to access them from other FSMs while local events can only be accessed as transitions to other states in the same FSM...
« Last Edit: August 27, 2015, 10:50:18 PM by Grendal »