Day 94 — Getting the Moving Platform and Elevator Working

Hey and welcome!

Last time we recycled our old code to get our collectable working again so let’s have a look at what’s needed for the Moving Platform which isn’t actually too much. The code is perfect the way it is and doesn’t need any additional edits since it’s not calling any specific methods from other scripts and is all pretty self-contained since it’s just focusing on its own movement and the trigger enter and exit methods when the Player hops on.

All that’s needed to be done here is to duplicate the desired platform twice to mark out our TargetA and TargetB transform values that our script is already looking out for and then turn the mesh renderer of the objects off.

Lastly don’t forget that this platform needs a box collider attached to it that is just a bit higher than the platform itself so that the player can trigger it, this one doesn’t need a rigidbody to work.

When you’re happy be sure to add your moving platform and targets as children to an empty object and prefab that object so that you can use it multiple times in your scene. Remember that the script is written in a way that the movement is limited to horizontal only!

Now it’s time to get the elevator back and working but this time it’s going to function a little differently. It will still function the same way but this time the elevator itself will look out for when the player presses the E key instead of having a separate panel..

This also means that I don’t need a separate script now so I can just recycle the code I had in the ElevatorPanel script and copy and paste it into the Elevator script.

I also edited the code here removing the parts for changing the material colour of the panel light from red to green.

Now similar to the moving platform we need to add in two points that the elevator can move between which is the origin point and the target point. Also similar to the moving platform a box collider needs to be added that sticks out of the floor so that it can trigger when the player enters, exits and now, stays in the collider too.

That should be it all working but I’m not done with this elevator yet! I’m going to add in something a bit new, an extra floor/stop for the elevator and also a 5 second pause as it reaches each floor and the elevator will continue going after pressing the “E” key just once.

First things first is to create a new point in the middle of the elevator, this will be the new floor that the elevator will stop up before it gets to the bottom and before it gets to the top when it heads back up.

With that we have everything working as it was before, these two articles will probably be the only time that I’ll talk about reworking older code into a new project since everything has been covered and in this particular instance all three scripts that we carried over ended up having their own unique challenges to them when porting them over.

In the next one it’s back to new stuff!

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.