Moving Platforms in Unity3D

This is a short example of moving platforms in Unity3D.

Based on this tweet, I spent … 30 minutes? Maybe? putting it together.

This writeup took longer.

The approach uses two behaviour classes to achive the classical effect of moving platforms that follow some path.

  1. mark some empty GameObject as Waypoint instances
  2. give each Waypoint a next field
  3. attach a Mover instance to your platform(s)
    • drag the platform towards the next Waypoint at a fixed rate
    • when you’ve reached the Waypoint, continue with its next one

My example;

  • uses the concept of fuel to avoid losing movement when fast moving platforms don’t have far to travel
  • provides some Gizmo logic to make looking at it easier

Normal Unity3D Rigidbody instaces will impact with normal cubes - so if your platforms have a collider you’re all set. If you need-need Rigidbody platforms; you can make them Kinematic to avoid weirdness.

The platform will stop when it reaches the “last” Waypoint so you could modify the Mover to move backwards, or, just have the last platform point to the first platform and create a loop.

Peter LaValle avatar
About Peter LaValle
Peter is currently a PhD student at the University of Nottingham. His day work involves applying functional programming to problems with artificial intelligence. Someday maybe he'll retire and be a graphics programmer or demoscene coder.
comments powered by Disqus