Making the Game: A Simple Puzzle
Having created the shockwave gun, I was ready to move on to what would act as the game's primary gameplay puzzle: Getting so-called "Cube keys" to "Cube-activated buttons" in order to open a door. Just as in the previous Robotrooper instalment, these puzzles will slowly grow in terms of complexity throughout the game.
First, I created models for the cube key, button and door by placing a few box brushes in the scene. Brushes are simple geometric shapes which can be used to create models of a limited complexity. After playing with the brushes and their "brush types" (additive or subtractive, i.e. whether they add or remove bits from the overall shape), I applied materials to their surfaces and converted them into static meshes, a process I still remember from my Foundation Year. I also added Simple and Complex collisions on them, which will make them "solid" in the game.
Then it was time to create their blueprint equivalents. Blueprints in Unreal Engine are very much like prefabs in Unity, a class of objects that is reused many times throughout a game or level. Creating one is simple. To use the previously created static meshes as the root objects of their equivalent blueprints, I need only select them in the editor and click the blue Blueprint/Add Script button in the Details panel. To have a separate root, one could right-click anywhere in the Content Browser to open a menu, which also allows for the creation of blueprints, among other things.
After setting up all previously created meshes as blueprints, the first I began editing was the Cube Button.
I created two object type variables, one for the button's key (MyKey) and one for its door (MyDoor). I ticked the Instance Editable option, which is basically UE4's equivalent to Unity's SerializeField. This will allow me to assign specific keys and doors in the scene to a specific button.
Afterwards, I added a trigger box on top of the button. I used the trigger box to create a On Component Begin Overlap event. I dragged its "Other Actor" pin out to an Equal node, where I compared the overlapping actor with the "MyKey" variable. The result of that was fed into a branch node, which went on to validate if the "MyDoor" variable was not null. So if this button's key was suddenly overlapping the trigger box and a door was assigned to the button, that particular door would open.
However, I did not yet have a way to open the door, so I had to set that up before continuing. I created a Custom Event called "Open Door". Custom Events are a sequence of nodes that will be executed when the event is called.
Anyway, I wanted to animate the door using the Timeline node, but I was not fully sure how it works as it's been a while since I had used it, so I had to look up a tutorial to refresh my memory.
Basically, a Timeline allows you to change a value, be it a float, vector or something else, over a certain period of time. This is why it is perfect for simple physical animations, such as opening a door. Using SetRelativeLocation in conjunction with the Timeline to set the door's new position to its starting position (the "Door Closed Location" vector variable) plus an increase of 220 units on the Z axis set within the timeline should get the door moving as soon as the event is triggered from the Cube Button... Or so I thought.
I placed the newly made blueprints by dragging them from the Content Browser into the scene. I made sure the Cube Button knew which key should activate it and the door it should open by setting them in its Details panel. I tested this set-up several times by firing the cube at the button, but the door did not open. Why door, why?! I was stumped.
After some trial and error, I realised the key was not set to generate overlap events. This means that the cube was not detected in any overlap events. Thankfully, that was an easy fix. After ticking a simple check box, everything worked perfectly!
Anyway, here is a video of the cube and key functioning as they should:
Finally, something that works... though it's not yet what I would like it to be. I will try to make the cube key snap into the button slot and hopefully you'll hear more about that in my next post!
First, I created models for the cube key, button and door by placing a few box brushes in the scene. Brushes are simple geometric shapes which can be used to create models of a limited complexity. After playing with the brushes and their "brush types" (additive or subtractive, i.e. whether they add or remove bits from the overall shape), I applied materials to their surfaces and converted them into static meshes, a process I still remember from my Foundation Year. I also added Simple and Complex collisions on them, which will make them "solid" in the game.
Then it was time to create their blueprint equivalents. Blueprints in Unreal Engine are very much like prefabs in Unity, a class of objects that is reused many times throughout a game or level. Creating one is simple. To use the previously created static meshes as the root objects of their equivalent blueprints, I need only select them in the editor and click the blue Blueprint/Add Script button in the Details panel. To have a separate root, one could right-click anywhere in the Content Browser to open a menu, which also allows for the creation of blueprints, among other things.
After setting up all previously created meshes as blueprints, the first I began editing was the Cube Button.
I created two object type variables, one for the button's key (MyKey) and one for its door (MyDoor). I ticked the Instance Editable option, which is basically UE4's equivalent to Unity's SerializeField. This will allow me to assign specific keys and doors in the scene to a specific button.
Afterwards, I added a trigger box on top of the button. I used the trigger box to create a On Component Begin Overlap event. I dragged its "Other Actor" pin out to an Equal node, where I compared the overlapping actor with the "MyKey" variable. The result of that was fed into a branch node, which went on to validate if the "MyDoor" variable was not null. So if this button's key was suddenly overlapping the trigger box and a door was assigned to the button, that particular door would open.
However, I did not yet have a way to open the door, so I had to set that up before continuing. I created a Custom Event called "Open Door". Custom Events are a sequence of nodes that will be executed when the event is called.
Anyway, I wanted to animate the door using the Timeline node, but I was not fully sure how it works as it's been a while since I had used it, so I had to look up a tutorial to refresh my memory.
Basically, a Timeline allows you to change a value, be it a float, vector or something else, over a certain period of time. This is why it is perfect for simple physical animations, such as opening a door. Using SetRelativeLocation in conjunction with the Timeline to set the door's new position to its starting position (the "Door Closed Location" vector variable) plus an increase of 220 units on the Z axis set within the timeline should get the door moving as soon as the event is triggered from the Cube Button... Or so I thought.
I placed the newly made blueprints by dragging them from the Content Browser into the scene. I made sure the Cube Button knew which key should activate it and the door it should open by setting them in its Details panel. I tested this set-up several times by firing the cube at the button, but the door did not open. Why door, why?! I was stumped.
After some trial and error, I realised the key was not set to generate overlap events. This means that the cube was not detected in any overlap events. Thankfully, that was an easy fix. After ticking a simple check box, everything worked perfectly!
Anyway, here is a video of the cube and key functioning as they should:
Finally, something that works... though it's not yet what I would like it to be. I will try to make the cube key snap into the button slot and hopefully you'll hear more about that in my next post!








Comments
Post a Comment