Skip to main content
December 13, 2013
Question

How to make a vertical lift or elevator in a platform game

  • December 13, 2013
  • 1 reply
  • 3604 views

I am creating a side scrolling platform game using the book "Flash Game University" by Gary Rosenzweig.

My protagonist has an instance of "hero".


My current issue is trying to create a lift or elevator to carry the player up or down. The lift is not covered in the book. My thoughts were that the lift constantly moved up and down at a pace determined by a timer. I cannot get my lift to move. I have created a movie clip called "lift" and made it exported for action script. I can make it act similar to a floor movie clip so that I can stand on it, but I cannot get the lift to move on the y axis.


I tried creating a new function called lift() and using a for loop to count between 0 and 100 using a variable "i" and then make my lift move up 1 unit for each loopcycle. It didn't work.


lift.y -= lift.y - 1;


Does anyone have a better solution?


Thanks,

Alex

This topic has been closed for replies.

1 reply

Participating Frequently
December 13, 2013

you probably want to rename your lift function to some other name then your lift instance name and use onEnterFrame to to call your lift function at frame intervals.

December 13, 2013

I added the following code, but it still does not work.

                                        stage.addEventListener(Event.ENTER_FRAME,moveLifts);

public function moveLifts()

                              {

  this.lift.y -= 105;                 

}

ajdove
Known Participant
January 3, 2014

1. When I am on the elevator I cannot jump. If I am not on the elevator I can jump normally.

You will have to look at the code that allows your charactor to jump. There is a variable somewhere that is changed when the charactor is in the elevator.

2. When I touch any portion of the elevator, my character automatically repositions itself to stand on the elevator. It seems normal, but not something that should happen in my scenario. I only want to "climb" on the elevator if I touch the "top" of the elevator.

I have no idea. Whatever you are doing to get the charactor into the elevator is being called when you touch the elevator, I'm guessing.

3. If I add a second elevator, even with its own function, the timing of the elevator math appears to synch instead of work independently. Why? The two elevators synch their movement and timing. Also the first elevator stutters as the synching of the two elevators match thier movement and then moves in unison with the second elevator. Why are they not operating separately?

Both elevators are run from the the function "gameloop". They both start at the same time and they both have the same movement increment, so they will both run in sync.


In response to #2: I tried to add a new child mc called "foot" to my hero. I created this mc and placed it inside the hero mc. I also gave it an instance name of "foot". I then tried to call the hitTestObject of the elevator only when the foot of the hero collides with the elevator. It is not working but I think it should.

here is my code:

//Inside my constructor I added

private var foot:Object;

//Inside the createHero() function I added the instantiation of the foot mc using

foot = new Object();

foot.mc = gamelevel.foot;

//Inside the moveMyLift() function I changed the hitTestObject using

if (box.mc.hitTestObject(foot._root.mc))

{

hero.mc.y = box.mc. y;

}

Any ideas how to fix this?

Thanks