Journal 86 — Unity 2.5D Platformer, Add a Moving Platform Prefab

Objective: Add a moving platform to 2.5D Platformer assets and turn it into a prefab so it is modular

In this article, I am adding additional functionality to a 2.5D platformer that already has 3D assets. I will turn an existing platform into a moving platform with a target and destination. Then after this is working, I will turn it into a prefab so it can be duplicated in other parts of the game.

First we can update one of the basic platforms and create an empty parent object and include the entire platform and game objects for a target A and target B.

On the Platform, we can add a RigidBody and Box Collider with trigger. Make sure the RigidBody includes constraints for x, y, and z rotation.

Now we can make a C# script for the moving platform. We need two game object transforms for the move points, and a speed variable, and a bool to change the direction. Then similar to the elevator behavior, we use Vector3.MoveTowards for an origin and target, and the bool to change the direction. We use OnTriggerEnter and OnTriggerExit to make the platform the parent of the player and remove the parent, respectively.

We can add this script to the Platform and test it.

Finally we can drag the moving platform into the prefabs to see if the platform and move points can be turned into a module. Then, we can move the moving platform to another location in the scene and update the Points A and B.

Thank you for your time!

--

--

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
Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.