Create Moving Platform in Unity.

The first step is to create a platform object in the scene (in this case i am using a 3d model with a collider) and create two empty objects with the position a and b to move the platform.

We have to create a new script called moving platform and add it to the moving platform object. In the script we have some vector 3 variables to store the initial a position, b position and currentTarget. And some variables related with the movement like the speed.

In the start function we have to initialize the point A and B with the position of the point A and B game Objects (we don’t use the position of these objects for the calculation because they are moving with the platform).

In the Update method we check if the platform reached one of the points to move to the other and use the function MoveToward to move the platform the current target by assigning the result of the function to the platform position.

And that’s it we have a functional moving platform in Unity.

--

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
Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.