playMaker

Author Topic: Opening and Closing a door  (Read 2887 times)

everlite

  • Playmaker Newbie
  • *
  • Posts: 3
Opening and Closing a door
« on: February 22, 2016, 03:36:29 PM »
Hi!

I'm trying to accomplish the simple task of creating an animated door that opens and closes when the user clicks on the door.

I've watched various video tutorials that seem to describe the process, however it seems like the tutors were using a different or older version of Playmaker. also noting the tutorials were around 5 years old,  I don't see the same options outlined in the tutorials i've been watching.

Could someone please outline the process of creating a door, that when clicked goes into an open state and when clicked again goes into a closed state. Specifically, how the animation is handled.

For the most part I can accomplish this task, however, i can't seem to get the door to close again, with respects to the animation.

On a side note, another question. How does one deal with multiple animations? by that I mean, in the above case I have two animations, open and close. If I create the animation in 3ds Max, do I need a separate 3ds Max / FBX file per animation? or do I do the complete animation in one file and some how read the specific frames in Unity?

Thanks
David


Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: Opening and Closing a door
« Reply #1 on: February 22, 2016, 04:01:00 PM »
Head into the Animator Window, and set up 2 states, "Open" & "Close". right click on "Open" state and click "Make transition"  drag that to the "Close" State.

We'll revisit that transition in a moment, but first, we need to create a Parameter. On the left side of the Animator window, there's a tab called "Parameters", click on this, and at the top (Next to the search field) there's a small "+" icon.  Click on this and select Bool from the dropdown. Rename this bool to "Boo_Open".

Now, click on your transition you set up before (click the line, not the state), and look to the inspector panel. Underneath the animation timeline is a section called "Conditions". Click on the little "+" Icon here and select your bool, and set the value to False. Now, when that bool is "False" it will transition from the "Open" state to the "Close state". You can set this bool to change from an FSM on a game object through the "Set Animator Bool" Action.

On your game object you'll also want to setup a bool value, again, we'll call it "boo_Open" (for consistency). When you click on the door, you want to fire off a "Bool Flip" Action, then a "Set Animator Bool". Set up the actions parameters so the Animator bool uses the bool value of your FSM variable. Now you'll see that when you click on the door, it changes your bool value in the game object and the Animator, and transitions to the "Close" state.

From here, you want to make a transition from the "Close" state back to the "Open" state, and set the condition to Boo_Open = True. Now, assuming this is set up properly, clicking the door should switch between the open and closed states in the animator window... Finally you need to select the animations you want to play on each state and drop them into the "Motion" section in the Inspector Panel on the relevant state (Click the state, not the transition).

In regards to your additional question:

When you import your animation file to unity, Click on it in the "Project Panel", and over in the "Inspector Panel" you have 3 tabs.  Select the "Animation Tab" and you'll see a section called "Clips". At the bottom of this section is a little "+" icon.  You can click this, and set start and end frames for an animation.
« Last Edit: February 22, 2016, 04:18:00 PM by Chizzler »

everlite

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Opening and Closing a door
« Reply #2 on: February 22, 2016, 05:55:29 PM »
Thank you, that sounds like a great explanation! I'm trying to follow through on your instruction and get a little confused on the following:

Quote
On your game object you'll also want to setup a bool value, again, we'll call it "boo_Open" (for consistency). When you click on the door, you want to fire off a "Bool Flip" Action, then a "Set Animator Bool". Set up the actions parameters so the Animator bool uses the bool value of your FSM variable. Now you'll see that when you click on the door, it changes your bool value in the game object and the Animator, and transitions to the "Close" state.

When you say again, where do I set up the bool value? I select the door object?

Thanks
David

Reef

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Opening and Closing a door
« Reply #3 on: February 22, 2016, 07:03:15 PM »
Hi, Ill try to pitch in...

 So you create an FSM on the door object: With the playmaker editor window open, select the door object and right click in the playmaker editor, then chose add FSM to door.

Then on the right of the playmaker editor window you have tabs like 'FSM, 'State', 'Events', 'Variables'. Click on the variables tab and add a bool type variable there.

Then like the previous poster said (I think), make a state which contains an action 'set animator bool value' and make it set the animator bool based on the game object bool.

Also for that you will need to download extra actions (mecanim action set) found here: https://hutonggames.fogbugz.com/?W1031

This includes the mentioned 'set animator bool' as well as other awesome animator actions.

Hopefully that helps you follow the answer above ,rather than confusing you through my rambling lol...

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: Opening and Closing a door
« Reply #4 on: February 22, 2016, 07:20:50 PM »
Exactly. From my understanding you've already got a system in place to listen for the mouse click, and find out what object you've clicked, if this isn't the door itself, there'll be a couple of extra steps to get the result you want... but for now, we'll assume it is (for simplicity).

So create the bool variable in an FSM on the Door Object itself... When a click on the object is detected, Flip the bool Value.. and your Set Animator bool will look something like this:

Game Object: Use Owner
Parameter: Boo_Open (Animator Parameter)
Set Value: Boo_Open (FSM Variable)
Every Frame: False

I forgot to mention that the door must have an Animator component attached, as this is what you'll be animating... you'll also notice that the Animator Window already has a state called "Entry", you'll want to create a transition from "Entry" to Either "Open" or "Close" with no conditions, otherwise it will never leave the entry state.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Now, if your door is not the game object that's listening for the mouse input (And realistically it shouldn't be, as you'll have more than one door in a level), you'll need to store the Game object that is clicked as a variable, "go_Selected" and test to see if it's a door object.
 If it is, you could "Send Event" to the door ("go_Selected")" to do the "Bool Flip" and Set Animator Bool" actions from the door object itself.

Why does the bool value need to be on the door? because if you have more than one door, you want each one to keep track of it's current state (whether it's opened or closed).
« Last Edit: February 22, 2016, 07:27:39 PM by Chizzler »