Okay! To start-off: Create a new UE4 project with the 3rd person view.
Create a new blueprint -> actor class and call it Elevator.
Add a new component at the top-left of the screen called StaticMesh.
Then choose a model for the static mesh at the right-hand side. Select ‘Shape_Cube’.
Set the scale axis (above the static mesh selector) for X and Y to 3.0, but then set the scale of Z to 0.1.
Compile, save, then head back to the tab of your main project.
Box collision setup:
Drag in your brand- new lift into your gameworld. By now you should have a flat square box in your game, if you play you will see your character step up onto it so we know the collision is working fine.
Now switch back into your Elevator blueprint and add another component, this time a box collision!
Go into your collision details like before and scale it 4.0 X, by 4.0 Y, by 1.0 Z. And then shift it up a bit with the move tool so none of the box collision is poking beneath your lift.
Now scroll down to ‘Collision Presets’ in the details tab still, click the dropdown menu and set it to Custom. Now, click the small arrow to the left of the box pointing right, and then scroll down ticking ignore for every object type EXCEPT pawn, leave that checked for overlap. We do this because we don’t want a random crate that’s blown away for example landing on the lift and triggering it to move.
Now scroll down and click the green box with a white + in the middle of it next to on component begin overlap. This takes you to a new window for some programming.
Blueprints:
In the event graph right-click besides event begin play and search for ‘Get Actor Location’ (don’t join these up). Now right click the yellow return value and select ‘Promote to Variable’.
Now join Event BeginPlay to the left of your new Set blueprint node.
Click the Set node and at the right name it to ‘IL’ (short for Initial Location).
Move down to the ‘On Component Begin Overlap’ blueprint node that’s already made at the bottom (or right-click and make a new one if it’s not there). Now drag a line out from other actor section and select ‘Cast To ThirdPersonCharacter’.
Now drag in your Box component at the top-left of your screen, then drag away to link up a node and select ‘Destroy Component’. This is to make it a one-time lift that takes the player higher without it needing to be used again in the level.
Now link the top-right arrow of Cast To ThirdPersonCharacter to the left of DestroyComponent. Now we will move on to something new: Timelines!
Timelines:
Right click the screen and select ‘Add a Timeline’. Then link DestroyComponent to the play from start. Section.
Double-click your timeline to open a separate window, basically we’ll be animating the lift to move up in this timeline when the player steps on it and collides with the collision box.
Click the V+ button to the right of F+ and left of i+ at the top of your viewport to add a vector track.
Set the length to 2 and then below that toolbar click the open padlock next to the red and green X and Y to ‘lock’ them and stop the lift moving in those directions, since we only want it to move up! This is important!
Hold shift and double-click anywhere in the box and set the time pop-up that appears to 0, and press enter. Now do the same thing and shift-click to create another point, this time setting the time to 2 (just the exact length of our animation) and setting the value to whatever you like (this will affect the distance your lift moves, higher values moving faster. I suggest you set it to 1000). The two dots should connect in a diagonal line like shown below.
Compile, save and go back to your Event Graph.
Vector Tracks:
Now we have our timeline done drag away from the yellow ‘New Track 0’ node we just made in the Timeline blueprint and select ‘Vector + Vector’.
Now drag in the IL variable we made earlier, select ‘Get’ and connect it to the bottom-left of the newly made Vector + Vector node.
Now in your Timeline_0 blueprint, drag away from the update arrow at the top-right and enter ‘SetActorLocation’. Now drag away from the left of this newly-made blueprint under the yellow ‘New Location’ and connect it to the right of your Vector + Vector node.
Results:
Compile and save, then switch back to the viewport of your main game and give it a play. If you move your character on-top of the lift and did everything correctly you should fly right up! Congratulations!
No comments:
Post a Comment