Minigame Monday: Seek and Shoot
Seek and Shoot:
- The concept:
Last week I made a minigame in Unity, so this time I wanted to make a minigame in Unreal. Although I haven't completed a major project in Unreal yet, I've been learning about developing with Unreal and in particular blueprints as a way of defining gameplay behaviour. For the gameplay itself, I decided to build on the first person example in Unreal, and make a game where you had to search around a play field to find and shoot a red target.
- The challenge:
Starting with the first person template helped a bit with setting up the game, but there was still plenty to do to adapt it to the game I wanted. For example, I didn't want the player to have to pick up the gun, so instead I edited the rifle's blueprint to bind to the player on game start. To create the target, I created a prefab, and then wrote a blueprint that would handle when it was hit. To keep track of the score and the time, I created another blueprint class that would store variables for the player's score, and also the time remaining to the player. The section of the blueprint handling the time looked like this:
You can see three variables I've used here; Seconds, Start Time, and Game Time. Seconds is pretty self explanitory. When the seconds change, the first branch is false, and the execution continues, setting Seconds to the new value. Start time is a variable used to allow the game to be restarted. When the game is restarted, this variable is set to the current time (in seconds). Therefore after the first subtraction, the value will be the amount of time in seconds since the game has started. The last variable, Game Time, stores how long the player has. After subtracting the current time the player has been playing for, this value is then passed off to the right to be shown on screen. If this value is zero, the player is out of time, so the right most branch will catch and handle that.
Another challenge was making sure the target would spawn randomly, but not inside any other object. The solution I found for this is below:
This was being called when a target was hit. If I'd had more than a day, I'd have made this blueprint section a function, because the same functionality is used to spawn the first target at the very start. To explain the functionality, a random location is produced, then the blueprint attempts to spawn a target at that location. Note that "Don't spawn if still colliding" is selected. If the location is within a wall, an object won't be spawned. The 'Is valid' block checks if the result of the spawn is valid (i.e. an object has been spawned) and if the result is not valid, it will attempt to spawn again until a location has been found. At that point the blueprint will destroy itself (the target that was hit).- The result:
Although this game is pretty basic (as you would expect from a minigame and my first game in Unreal), it's functional and searching for the targets and finding the best place to shoot them from is pretty fun. You can download the game from https://reddragonmakesgames.itch.io/seek-and-shoot
Comments
Post a Comment