playMaker

Author Topic: Controlling an elevator  (Read 9490 times)

terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Controlling an elevator
« on: May 11, 2012, 10:07:20 AM »

I couldn't get my playmaker elevator going, so I ripped off the one in the Unity 2d platform tutorial, it's at unity3d.com
resources/tutorials.


Once completed the elevator just goes up and down forever.

What I'd like is to be able to start and stop this elevator with a automatic trigger, like the noob door example, and also
start stop at bottom and top with buttons like the noob door buttons tutorial. And later with a mouse click
on the button.


unity3d.com/support/resources/tutorials/2d-gameplay-tutorial

Here are the components

1. the platform, called "MovingPlatform" it's a prefab (denoted by the blue cube) that is in level prefabs and also in platforms I didn't export any
moving platform effects, but I did copy the 'platformMover.js' script into my assets/scripts/2d/MovingPlatform , it didn't export with the assets/export unitypackage, I had to go /assets/import new asset to get it to show up. I
dragged it onto the prefab. Note the MovingPlatform had to be scaled to .23 to fit in my default scene.

Components from page 32 of the 2dgameplaytutorial.pdf, note you can save these things as .txt with the free Foxit reader, although it might look weird.

• Box Collider
  Without the Box Collider, the character and other objects would fall right through it!

• Rigidbody
  This also allows the crate to physically interact with the character and other objects. A 
  few settings deviate from the default. "Use Gravity" setting is off. The "Is Kinematic" 
  setting is on. The "Is Kinematic" setting prevents the character or other Rigidbodies 
  from moving the platform somewhere besides its predefined path. 

• Configurable Joint
  Like the Rigidbodies described in the previous section, this component restricts our 
  movement. Everything is the same except now ALL rotation is forbidden:

    ZMotion: Locked

    Angular XMotion: Locked

    Angular YMotion: Locked

    Angular ZMotion: Locked

    Configure in World Space:  Checked

                                                                                         33

----------------------- Page 34-----------------------

• Pipeline, Mesh Filter, and Material
  These assign the proper mesh and texture so it renders in the scene. '
   end 2DGAMEPLAY.PDF



There are 2 game objects also needed 'PlatformTargetA' and 'PlatformTargetB, which has a little .tif file to show where it
is in the scene view, this was in /Gizmos, so I just copied it over into gizmos.

// This script must be attached to a game object to tell Unity where the Moving Platforms should move to.

// We'll draw a gizmo in the scene view, so it can be found....
function OnDrawGizmos() {
   Gizmos.DrawIcon(transform.position, "platformIcon.tif");
}


PlatformMover.js attaches to MovingPlatform
var targetA : GameObject;
var targetB : GameObject;

var speed : float = 0.1;

function FixedUpdate () {
   var weight = Mathf.Cos(Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5;
   transform.position = targetA.transform.position * weight
                  + targetB.transform.position * (1-weight);
}

Note the Target B was at the bottom and the Platform begins at the top Target A


So drag the targets over onto the script. 1 more thing, select the platform and add a /component/physics/box collider,
otherwise you can't ride the elevator.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Controlling an elevator
« Reply #1 on: May 11, 2012, 03:47:14 PM »
Ok,

 Let's start from scratch... the lift issue is something that happens to a lot of users, so let's get this sorted once for all :)

 Please find attached a working scene with a proper lift prefab, doing quit a lot, and surely answering your needs... at least I hope, and if not, it will give a you a good head start to modify or build your own.

----------------------- WARNING ----------------------
 this package uses global events, and them global events have been exported properly, so when you import it, make sure you import globals ( in the tools menu of playmaker) before working with it.
---------------------------------------------------------

Features:

-- A set of global events enables other fsm to control a particular lift, All them events are organised and starts with "LIFT /" so it's easy to find them
-- the lift set up is relatively complex, but allows for maximum flexibility, you have the up and down targets where the lift should stop, and you can swap the platform mesh without loosing the functionality
-- the lift can be toggled at anytime, so as it goes up you can ask it to go down ( thank you iTween! )
-- the lift can be locked, and unlocked at will, this is important in some games where you want to spice things up
-- the lift platform as a small trigger in its center that you can use to auto trigger the up and down movement of the lift, you can of course control if from external sources by just calling the proper "LIFT /" event on that lift
-- this platform trigger can also trigger a toggle when it exit, making the lift completly automatic: the user arrives, is taken up or down, and when he goes away, the lift comes back to where it was. I gave you the abiliy to define this without modifiy the fsms ( it's in the Fsm inspector).


The scene I have included, shows two lifts, and to actually use them both with your player, you will have to first go to the one that is on the floor ( you'll see the second one going up as the scene starts), it will take you up. you'll pass a trigger that will lock that lift, so you will have to use the other one to get down ( without jumping off the second floor of course...) and then you can call the first lift back, by going towards the trigger on the floor .

So with this prefab, you can build a lot of different lifts, some that goes higher then other, you can adjust the speed, you can change its appearance, etc etc. You can even move the up and down targets to have one lift going to different floors! how about that :)


 If you have any questions, don't hesitate to ask,

Bye,

 Jean

terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Re: Controlling an elevator
« Reply #2 on: May 13, 2012, 09:55:29 AM »
Thank you, I was about to copy Steve Gargolinski's elevator when I saw this post, yours is better and it
works. The globals_exported import when you import custom unitypackage, when I went tools/import globals
it deleted them so I had to go tools/import globals again.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Controlling an elevator
« Reply #3 on: May 13, 2012, 12:00:22 PM »
hi,

 I think it is the expected behavior that when import globals the assets are removed, because essentially they are just here to cover importing packages without corrupting the existing internal global asset from playmaker, so the asset created when exporting globals is only a tempory placeholder.

 Alex will correct me if I got that part wrong :)

 bye,

 Jean

terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Re: Controlling an elevator
« Reply #4 on: May 20, 2012, 12:20:26 PM »
I'm trying to start the elevator by using the mouse cursor door button thing in the samples, I got the
button, cursor in there but it's not starting the elevator, I don't think I have the trigger box controlled by
the button.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Controlling an elevator
« Reply #5 on: May 21, 2012, 01:30:43 AM »
Hi TerryMorgan,

not sure what is your question.

-- looking at "DoorButton", you have no Fsm there, so do you want that to trigger the elevator?

-- looking at "cube", you have some kind of FSm but nothing plugged to send an event to the lift the event "LIFT / GO UP" or else.

 So what are you trying to achieve with these two gameObject?

What do you mean by "button", do you expect the user to click with the mouse, or do you expect the button to react to the player presence ( triggering automatically when it triggers).


bye,

 Jean

terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Re: Controlling an elevator
« Reply #6 on: May 21, 2012, 12:33:41 PM »
Hi Jean,

Maybe not everything got into the unitypackage, but I want to take the button mechanism
from
playmaker samples/testlab/triggers/ ButtonDoor.unity file

And use it to control your elevator. The button has the fsm it sends event to the Lift called LIFT/GO UP,
but I think the trigger on the Lift isn't controlled by the button, because the lift goes up when I collide with the
lift trigger.

terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Re: Controlling an elevator
« Reply #7 on: May 21, 2012, 12:37:22 PM »
Here's the package

terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Re: Controlling an elevator
« Reply #8 on: May 04, 2013, 09:36:41 AM »
I just tried this in unity 4, (and 3.5) playmaker 1.5.7, in both I get this 'error', however the lift
works fine, should I worry?  I put the 'go down' button at the top of the elevator.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Controlling an elevator
« Reply #9 on: May 07, 2013, 02:36:28 AM »
Hi,

 Yeah, I get the same, I just tried. I have submit this to Alex

to fix this, do the following:

 open the "lift" prefab in your assets ( not in the scene, in your assets).

 Then open the "events"  tab of the "Lift" fsm, and tick all "LIFT / ***" so that are global again. basically, playmaker lost track that these events are global.

Bye,

 Jean