GameDevHQ Crash Course #28 Elevator Systems, Wall Jumping and Object Movement.
Elevator System.
Now that we have moving platforms down, making elevators will be a breeze, as we just need them to move when commanded instead of automatically.
first we need a zone for the player to be in for the elevator to be callable, so lets add a box object to our elevator panel and extend it out to the elevator platform, this way we can call the elevator up when on the elevator as well.
Then we attach a script to this box that when the player enters and presses a button, in our case we are going to make that button E, it will talk to the elevator script and start its movement down to point be, we also added a requirement that the player needed 8 coins to call the elevator. for this we are just calling a public method from the ‘other’ collider as long as it is the player.
And same as the moving platform we need to make sure it is running under a fixedupdate and parents the player to make sure we stick to it and are not jittering while moving.
Wall Jumping.
Next lets add some more movement options, we have this tall corridor that the player needs to move up, we cannot double jump up, it is too high, so lets add some wall jumping.
For this we are going to be using some more features of the character controller. First we tag these walls with the tag “wall” so we can easily separate them for our double jumping purposes
First we need to find the hit point on the wall and since we want this value to be consistent we need to normalise the value. Then we multiply the value by our chosen speed and add upwards velocity to it, tweaking these numbers to get something that we like the feel of.
now we are a move awesome way of moving ourselves up a wall.
Object Pushing
Finally for this one we are going to push an object along a path and onto a pressure pad.
First we add ourselves an object to push and a platform to push onto. We are going to use a box and a rectangle respectively.
Then we add ourselves a rigidbody onto the box so we can apply gravity and interact with it.
However for this rigidbody we also want to go and freeze the rotation of it, we don’t want our box to be rolling as we are pushing it at a consistant force all across its side.
Then we check our tags to make sure we are hitting the moveable box, and if we are we apply a velocity to the object to match how much we think the box ‘weighs’ so if we want the box to ‘feel’ heavier, we make the movement slower, or have slower acceleration.