Moving Platform A Different Way

Create a moving platform that’s modular and turn it into a prefab

James Lafritz
Dev Genius

--

To create this Platform I am going to use Cinemachine Smooth Path for my way points to follow, much like I did in this Article.

I will not be using a Dolly Cart for this, because I do not want to change the rotation of the platform, Instead I will be using Vector3.MoveTowards like I did in this Article with Transforms.

Blending the advantages of both together.

I create an Empty Game Object To house my moving platform. I add my Platform Prefab to it. I made it so both ledges are grabbable by turning on the grabbable ledges and turning off the normal ledges. I then add a

I start off with the basics that I need to make it move.

I fill in the Update Method.

I then fill in the Next Position Method. to get the Next Position I use the Cinemachine Base Path Evaluate Position At Unit Method. This Method returns the Vector 3 at the position given determined by the Position Units Given.

I add the Moveable Platform as a Component to the Moving Platform and set the Values in the Inspector, I then turn this into a Prefab.

Now that I have a Prefab for it I set up the Moveable Platform to the position I want and the create the Path for it to Follow.

Now I fix the Issue of the Player not moving with the Platform by setting the Player’s Parent to the Platform when the Player enters the Platform and setting the Players Parent to null when it exits the platform.

Since the Trigger is on the Platform and not the Moving Platform Main Object I need to add a Rigidbody to the Moving Platform so the Trigger Collision can happen. Also I should Be using Fixed Update not Update, and I need to set the Players Parent to the Platform Transform.

Also when the Player performs a Ledge Grab The current Set up turns the Character Controller off which means the Player Exits the collider and no longer moves with the platform.

To Fix this is as simple as Checking to see if the Player is Ledge Grabbing or not before setting it’s Parent to null.

Adding the Ledge Grabbing ScriptableObject to the Moving Platform Prefab

I also had to change the Box Collider Trigger on the Platform, It was not big enough on the Z Axis to collide with the Player while doing a ledge grab.

Now I have a Moving Platform that the Player can grab onto.

One thing that I have to consider is the fact that the Player does not use the physics system while ledge grabbing so I will have to ensure that any moving platforms can not move in such a way that the Player might collide with something.

--

--

Excited about changing my hobby into a new carer with GameDevHQ course.