Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: KurdLegend on March 20, 2012, 03:01:31 PM

Title: Simple interaction between 2 gameobjects
Post by: KurdLegend on March 20, 2012, 03:01:31 PM
Hi There, just a little background on my game, its an RC Car which must get a diamond which is located on top of a tower of blocks. By hitting the tower of blocks, the Diamond drops on to the back of the RC Car and the player tries to drive it to a elevator which will bring the diamond back up to the surface where the level will finish.

So my question is simply, how do i set up the gameobjects ( the diamond and elevator) so when they touch each other there is a 5 second wait, after the wait if the diamond is still on the elevator goes up the Y axis and the level is cleared

Any help will be really appreciated as i just bought Playmaker and im still learning it :)
Title: Re: Simple interaction between 2 gameobjects
Post by: justifun on March 20, 2012, 03:27:32 PM
The action "Trigger Event" is going to be what you need for this one.
https://hutonggames.fogbugz.com/default.asp?W37

Your going to want to create a box collider on your elevator, around the area where the car is going to drive into it.  Make sure you check the box labelled "is trigger" on it.

Create a new tag for your diamond prefab and call it "Diamond" for example
You could give you player character a tag instead if you want too.

On your elevator prefab you will have a initial state that will sit there and wait for a diamond to enter that colider area.

So state 1 would simply have the trigger event action.
and one transition event that you could call "goToElevatorUp" or something.

Use the following settings on the trigger event
Trigger: OnTriggerEnter
Collide Tag: Diamond (or the player's tag if you want the car to trigger the next event)
Send Event: goToElevatorUp

In state 2 next to state 1 on your elevator you can use a "wait" action, and give it a value of 5 (for 5 seconds)
then add a "finished" event transition by right clicking and choose add transition, then right clicking the ... grey box and choosing "FINISHED" (so after the 5 second wait it will go to the next state.

State 3 will have the "translate" action, and you would put a value into the Y axis (and check the box labeled "per second")

This will make the elevator rise # units vertically per second.

You could also use a "itween move to" instead of translate if you want to use the nice sexy ease in and ease out movement to the elevator as well.

If that's the case, make an empty game object to use for the itween "transform position" value so that it knows where to go (up off the top of the screen or wherever).  Place it directly above your elevator at the top of the "shaft" or something.

In the "Finish Event" section of the itween move to action, you can have it trigger off some other state (like adding to the players score) or moving the elevator back down etc.  Just add a event transition (eg: goBackDown)to the same state as the itween move to action , and then populate it in that field that says "Finish Event"

Hope that helps!

ps. you could also animated the elevator in a different 3d package and use the play animation action to start / stop animations of the elevator as well.

for more info on triggers, check out this screencast tutorial
http://www.screencast.com/users/HutongGames/folders/PlayMaker/media/781369f4-7582-469e-8673-95af83761b0e


Title: Re: Simple interaction between 2 gameobjects
Post by: KurdLegend on March 20, 2012, 03:44:28 PM
wow your awesome, thanks so much for writing that tutorial, but im a little confused on this bit:

Use the following settings on the trigger event
Trigger: OnTriggerEnter
Collide Tag: Diamond (or the player's tag if you want the car to trigger the next event)
Send Event: goToElevatorUp


how do i make it so playmaker can check if the Diamond is the collide tag ? which action shal i use, i think im only stuck on this but, the other part seems easy to follow

thanks again for your help


EDIT - oh and when i tick Is Trigger on the elevator box collider, the elevator just falls through the ground :O
Title: Re: Simple interaction between 2 gameobjects
Post by: justifun on March 20, 2012, 03:53:02 PM
In the trigger event action you have to set a "collide tag" (the second option down). In your case "diamond" or whatever you tag your diamond prefab with.  This is telling unity that you only want this event to trigger if your object that has the event on it (in this case the elevator) colides with an object with the tag "diamond"

it will ignore all other collisions.

to recap

1-tag your diamond prefab with a new tag called "diamond"
2 - add a FSM to your elevator and in state 1 add a action "trigger event"
3 - Change "Collide tag" in the trigger event to "diamond"
4 - change the "send event" in the trigger action to whichever event transition you want (that you added in the event tab of the playmaker FSM eg: goToStartElevatorRise or whatever
Title: Re: Simple interaction between 2 gameobjects
Post by: justifun on March 20, 2012, 05:21:25 PM
The elevator is falling through the ground probably cause you have a rigid body on it, try removing that since you'll be animating it via translation instead of physics.