With weapon scripting and random generation already covered, I worked on scripting the interactive environment objects. We tried to have some form of interactivity in every room and make it vary so the game didn't get boring. We still have more rooms to make! I will cover a few blueprints I have made.
Crates were a cool little addition to make the game more action packed. Doing enough damage to crates causes them to break apart. Explosive barrels behave the same way, but do damage to anyone too close enough the explosion.
The first thing we have here is destructible crate. All things hit by player bullets use the code below, found in the projectile's blueprint.
And a simple damage blueprint in the crate makes the magic happen.
Controls Panels are an On/Off switches that can be triggered by moving near them or shooting them. They activate and deactivate objects in the environment and allow the player to progress.
The first thing done in the blueprint is that a short function is run to set up an instance editable material for the panel screen called "Panel Screen" This allows the material swap between red and green. The code below runs upon activation. It swaps the panel color, plays a sound effect and particle effect, and messages all connected objects to activate.
Platforms were one of the first obstacles we came up with for the game. We wanted to add more to the game than simply "kill to proceed". In order to progress certain rooms, the player must activate hidden platforms that rise up from the depths.
When the platform is activated, it runs a flipflop command that switches between one path and another each time its run. The top path moves the platform to the location of the invisible mesh shown below. The bottom path returns it to its home position.
The sentry turret was a fun idea that Drew DiCenso came up with and modeled. He created a base with legs to mount guns onto rather than making one complete turret. I then created a modular blueprint that allows the level designer to decide between four big weapon types: Rifle, Minigun, Shotgun, and Rocket Launcher. I created and instance editable light on the turret that would switch
First the construction script creates an instance editable material for the turret light. Then the turret weapon will either be decided at random or by the level designer. If it isn't random, the choice is based on which enum is selected. Since all the meshes for the four weapon types are part of the blueprint, the one selected is set to visible and the rest set to hidden. Then the fire rate and fire type is set.
At spawn, a health bar widget is added to the top of the turret. The turret's health is set to its maximum health, and the barrel of the minigun is set to spin (only visible if that weapon type is selected). Then the actor casts to the player to get a reference.
At the start of the game the the turret is set by default to be on, it's light is set to red and a red point light is set to a high intensity. Then it will activate an event called "Active Turret". If it turned off, it does the opposite. When switched, it always defaults "In Range" to off. I will cover this later.
ActiveTurret runs three commands: TrackPlayer, CheckForPlayer, and Shoot, whose loop rate is determined by fire rate.
Over in "CheckForPlayer", a multi-sphere trace is run in the turrets range to detect characters. Then it loops through all the detected characters, compares their range, and targets the closest one. If it is a new target, a bleep is played to alert the player.
Over in "TrackPlayer", the function checks to see if the turret is active and the target is in range, then gets both its own location and the target location, and rotates the gun along the Z axis to face the target.
In "Shoot", as long as the turret is active and the target is in range, it will fire one of the four types.
One of the fire types is pictured below, the necessary particles and sound is spawned, then the projectile.
Boilers, as well as pipes, were created to hinder the progress of the player by pushing them into pits and other hazards with intense bursts of steam.
First, a delay time is chosen at random. Then the boiler turns on, which consists of activating a looping steam sound, activating particles, and activating a collision box. Then another delay is chosen at random and the boiler turns off, doing the opposite commands previously mentioned.
Then, when the player overlaps the trigger box where the steam is, the player is pushed by an event called "Conveyor" (This was first made for the conveyor belt). This runs in the player blueprint. The event interface checks if the conveyor is active, then gets its direction. From there, it sets whatever the last conveyor was as the current one (to avoid overlapping and doubling the speed unintentionally) and runs a gate that makes sure the player is still in the conveyor space and applies movement.