Nerd For Tech
Published in

Nerd For Tech

Lift Platform

This article will show how to make a Lift Platform that moves from floor to floor and pauses at each for a set duration. Since this functionality is similar to the Moving Platform from the previous article, the Lift will inherit from that script.

The LiftPlatform script will need a few variables to change how the inherited MovingPlatform functions.

  1. The amount to delay before moving to the next floor.
  2. A bool to know if the Lift is currently pausing at the reached floor.

In Start, we set the Lift to the starting floor Waypoint and change the current Waypoint index to the starting floor if there are Waypoints and the Waypoint exists.

To have the Lift pause when it reaches a floor, we will need a simple Coroutine that changes the pausing bool to true and then back to false after the delay.

Next, we add on to the CheckPosition method by overriding it, and after the base method has run to start the Coroutine, pause the Lift’s movement if it is at the current Waypoint.

Then to stop the Lift from moving if the Coroutine is running, we override the CalculateMovement method and only allow the base method to run if the Lift is not pausing.

The Lift Platform has a Box Collider set to be a Trigger with a Rigidbody like the Moving Platform. But, the Floor Waypoints are the edge piece of the Platforms, so the Lift will lineup nicely when it reaches that floor.

The Lift now moves between the floors and pauses at each floor.

This is the inherited MovingPlatform script for reference. For more on inheritance, you can see this previous article.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store