Thursday, April 23, 2015

ET 17 : Assignment 04: Unreal Tutorial

Timed Triggers Using the Matinee Method

This method is what I'm using in the Level Blueprint. We will set up a switch with a prompt to enable input, then set a wall to descend when the button is pushed.

Setup

The first thing to do is set up the switch so that your character is able to press a key to trigger an event. 

Place an instance of SM_Statue (Starter Content → Props) in your scene – this will be a visual representation of your switch, so put it wherever you want the switch to be. Then create a trigger volume in front of it, large enough for the character to stand in. Rename this volume (I named mine SliderTriggerVolume.) 


Right click on this trigger volume and select “OnEventBeginOverlap” from the Add Event option in the Collision submenu.

In the Level Blueprint, drag out from the OnActorBeginOverlap Other Actor node for the SliderTriggerVolume, and connect a Cast To MyCharacter node.


Then drag out from the Cast To MyCharacter pin and connect it to an Enable Input function. Drag a wire from the Player Controller pin and connect it to a Get Player Controller function. 

 
Next we’ll create a cue so that the player knows to press a button. So create a new String Variable, and name it Press F. Type “Press F” in the Default Value field. Compile now. 


Drag a wire from Enable Input and add a Print String function. Then create a reference to the Press F String Variable you just created (either click on it, right click and add reference, or just ctrl+drag it into the Event Graph. Connect the Press F string to the Print String function. Now when you enter the Trigger Volume, the player will receive a prompt to press F. 


Now we want to disable input when the character leaves the Trigger Volume, so that the F key can only trigger an event when the character is standing in it, and not at other random points.
Once again, right-click on the SliderTriggerVolume in the World Outliner, Add Event and this time select OnActorEndOverlap. 


In the Event Graph, once again, drag a wire from the blue “Other” pin to create a Cast To MyCharacter node. 


Then drag from the execution pin on Cast To MyCharacter and add a Disable Input function.


Finally, connect the Player Controller node on the Disable Input function to the Get Player Controller function (you can use the same one as before or make a new one, whichever you prefer). The final connection network should look like this. Draw a comment box around it and name it something useful, like Enable/Disable Input SliderTriggerVolume. 


Place an instance of wall_400x200 in the descending wall's starting position.



Add a new Matinee by selecting Add Matinee from the Matinee menu.


In the Matinee window, right click to Add New Empty Group, then - with the wall selected in the World Outliner - right click again to Add Selected Actors to Group. 


Right click again to Add New Movement Track. (No picture, but you know what you’re doing.)
Add a key at frame 0. For this tutorial, I have decided to give the wall a 10 second descent. So scroll in the movement track to 10 seconds (or however long you want this to take) and set another key. 

 Then in the main viewport, move the wall down to its final position.


If you are satisfied with the keys, close the matinee actor.

Select the Matinee Actor that you’ve just created in the World Outliner. Right click in the Event Graph to create a reference to the Matinee. 


Then drag a pin from the Matinee reference, and add a Play function. 


Then, from the execution pin on the left side of the Play function, drag a wire and connect it to F. This tells the game that when F is pressed, the Matinee should start to play. 


The final graph for the this part should look like this. 


Both graphs together look like this: 


Compile the graph and test it out.

If you want to add a delay before the start of the matinee, just insert a Delay function between the F event and the Play function, and specify how long to make the delay (here is one for 3 seconds). 


For this example, I have used the input event of pressing F to trigger the start of a matinee which closes a door. You can use this setup of input + delay to trigger any function you like, not just playing matinees.

No comments:

Post a Comment