Keeping the Player On a Moving Platform

Esteban Ibarra
Nerd For Tech
Published in
2 min readJun 23, 2021

So we’ve successfully written our moving platform, but our player won’t stay on it! Fortunately, there’s a simple solution and that temporarily parents the player to the platform. There’s a bit of preparation to do before but nothing drastic:

First, add another box collider to the moving platform and make it slightly higher than the platform. Also be sure isTrigger is checked. Also make sure a rigidbody is on so the trigger works, remember to set it to kinematic and turn gravity off to avoid a lot of headaches.

The rest is simple. OnTrigger enter: Parent the Player. When the Player exits, set the parent to null.

Let’s give it a go!

Wait…why did the player fall? Why isn’t it parented?

A little research will show that you need to be using the FixedUpdate() method which is specialized for physics objects that rely on Rigidbody like we are.

Ok…fingers crossed!

YES! Works perfectly!!!

Tomorrow let’s talk about modularizing the platforms.

--

--