Following on from the previous article, I’ve recently worked on a more modular moving platform based on the work we did awhile back. This largely consisted of me using one of my platform prefabs (‘Platform_Standard_Small’), unpacking it in the hierarchy, and then making my adjustments to it until I was happy with the result 😉
I added the MovingPlatform script to the platform model itself, then added two empty GameObjects to the parent platform object and renamed them to Waypoint_A and Waypoint_B respectively. I dragged both of these waypoint objects into the serialised GameObject slots on the MovingPlatform script, and set the serialised float variable (‘Speed’) to 5 in the Inspector.
Next, I selected each of the waypoint objects and zeroed out their Transform.position values, centering them on the parent object for consistency.
Finally, I dragged the finished GameObject into the Project window and into an appropriate folder under Assets.
The end result of this is a prefab I can quickly and easily drop into the scene, reposition the waypoints, adjust the platform’s speed, and move onto the next task 😄