Blue Skies
PLAY HERE!
Summary
This project comes from the idea of my team member Eric Vu. A 2D platformer where the main enemies have the unique ability to possess objects they see and can only be damaged while doing so. For this project, I've coded the enemy AI and possession mechanic, as well as providing the player health and respawn system.
The AI works as statically moving enemies which will randomly choose a valid possessable object in their search radius, as defined by the designer. Each ghostly enemy and the objects they possess are both controlled by a script that inherits from a parent script that defines most of their actions. It was necessary to have the objects controlled by this script as well because we wanted the object to move and attack the player when they become possessed by the ghost enemy. A majority of the AI actions are timed by coroutines with an adjustable period of time by the designer, including movement speed, how long the objects stay possessed, and the speed at which projectile enemies shoot at the player. |
An interesting challenge arose when we wanted a floating desk the player could stand on for a platform, with the added functionality that it was possessed like other objects, only as a passive entity that wouldn't attack. We also wanted the desk to naturally fall to the floor after the ghost leaves. Work was done to reconfigure the parent script of the ghost enemy to both allow for it to be passive to the player and function as a platform, but also make sure that objects with rigidbody physics, such as the desks, would be correctly handled by the script. The end result was a platform obstacle that floated in the air that the player could traverse, and would fall to the ground after the ghost left.
Utilizing Polymorphism for modular enemy design
One thing that I thought would be useful when creating enemies for this game is to have a central script for enemies that other enemy scripts can inherit from. Even though enemies may do different things in-game, their backend functionality is very similar. One advantage of using this singular script to inherit from is using virtual functions that different enemies may use to differentiate them.
This is basic polymorphism in programming, but using virtual functions in this way, specifically for the "OnPossessed" and "OnIdle", allows other scripts to call these functions and have them do different things depending on how the inherited script defines them.
Randomized Item Drops
A functionality requested by the project lead, randomized item drops from enemies adds to our health and ammo system in the game and provides a reward for players for defeating enemies instead of just avoiding them.
The probability of the drops are determined by a range of floats. This was the simplest way I found of having adjustable probability with multiple outcomes. To explain, since we didn't want both a health pickup and an ammo pickup to drop when an enemy is defeated, I needed to find a simple way of having mutually exclusive probability with a single generated random number.
This system has 3 outcomes of the random number generation; one, no drop is instantiated, two, an ammo drop is instantiated, and three, a health drop is instantiated. The min/max variables of each drop determines how likely each outcome is. In addition to the core functionality of the script, I also made sure other scripts could change the probability of the drop. This was done so that the different difficulties of demons (green, yellow, red) could have different probabilities for drops. Finally, this script was made with the thinking that it could be put on other objects, such as if we decide to add a destructible box or something similar. |