Repository navigation
Functional Design
Top-down/Isometric horde survival game In this game players need to defend a central base from waves of enemy hordes. Enemies continue to spawn in waves until the base is destroyed. The players need to keep defeating all the enemies until it becomes too difficult to keep up. If the base is destroyed the match will automatically reset after a short loss screen.
When the player first joins the game they will be prompted with a class selection menu. The classes all have different weapons and skills/spells The player can move along the x/z axis using WASD and can look and aim in a 360 degree radius using the mouse. Attacks can be performed with left mouse button. The player can attack and move at the same time. The executed attack depends on the player's selected class, weapon and projectile type. There are melee and ranged weapon type attacks. Players can also place structures on predetermined locations. These structures will help players defend from the hordes. Players can non-verbally communicate with each other trough emotes (social) and pings (tactical). If a player dies they will respawn after a short time.
Enemies will spawn at predetermined spawn points on the map and move towards the base, if a player gets close enough to them they will move to attack them instead. There will be several enemy types, some melee and some ranged. Ranged enemies are significantly less common, otherwise the game would become a total bullet hell. Only the weakest enemies will spawn in the early waves but as the game progresses stronger enemies will begin to spawn.
The unlocked weapons and projectiles/spells need to be bought in a shop during gameplay. The players start with no money on wave 1 and will gain money by killing enemies. When a player leaves or the game is lost and resets they will lose all bought items and money.
Players can build structures such as ballistas in order to help them hold back the horde. These structures will need to be built on pre-determined locations on the map. These structures can also be destroyed by enemies that get too close.
When you create functional design for a feature you should add it here
The player has to obey within the few rules it has with the following features is needed:
- Movement
- Attacking
- Buying in shop
- Emoting
- Building
- Gaining Damage
- Getting Currency
- Inventory
- Classes
- Minimap
At a determined distance of the base in each direction there will be enemies spawned. Then on each spawner location there will be an area where the enemies are allowed to spawn. In that area the enemies will be generated either randomly or strictly in a row depending on what we the developers want. The spawners will have access to all the enemies and with logic it'll spawn which enemy for which wave. After every enemy has been killed a new wave will occur. In the new wave there will be more enemies and the enemies themselves will have some extra health

In this visual sheet you can see the zones and the base(The distance between them and the zone size are not on the same scale as the image). In the green zones/the spawn zones the zombies are allowed to spawn in that region they are allowed to pick any range which is inside of the zone or every enemies will spawn in a row and drop down every collumn. They player isn't allowed to go inside of the enemy spawn zones.
The enemy has 4 main things to follow, like:
- Targeting
- Movement
- Attacking
- Dying

Targeting: The Enemy will target the nearest structure to attack, if the player is in range, despite the structure being the nearest target, the enemy will constantly follow the player and attack the player, because the player has the highest priority point to attack.
Movement: The Enemy is able to walk towards the target to attack them, which can be either the players or a structure. If they target the player, they will stop for nothing to catch the player, if the enemy is going for a structure instead, it will target and go to the nearest structure to destroy it.
Attacking: The enemy is able to attack the structure or player it's targeting, until the player or structure has 0 health which results in either killing the player or destroying the structure.
Dying: The enemy is able to die after the health of the enemy reaches 0 after the player or the structure that is attacking the enemy has shot them with a gun/ranged weapon or attacked them with a sword.
The player can spawn at any point which we desire. It will be flexible so it's adjustable to the map.
Health Features:
• Healing
• Setting max health
• Death
The universal health script has 3 main functions:
1: Setting the max health for objects which use the Universal Health script. The objects can differentiate in health so its required that we can set the health value via the inspector.
2: The amount of healing an object which uses the Universal Health script receives can differentiate per object and changes according to the healing source.
3: When an object reaches 0 health, the Death function will be called which causes the object with 0 health to die and either destroy or respawn depending on if its and enemy/structure or a player/structure.
When the player comes upon an place that isn't occupied and on an placeholder in the map, the player gains the chance to place an structure there to defend the main base against the enemies that try to attack the main base.

If the player is upon the placeholder site where they can build, they can open the shop menu, by pressing E, they have an list with structures they can choose to place.

After the structure is spawned in, the structure will target the nearest enemy and shoot at it until it's dead.

As stated earlier when joining the game the player must make a choice which class he wants to play as. Each class has its strength and weaknesses which each class has a different type of playstyle. Classes will have different weapons depending on their type, ranged or close range for example. Classes have a progression aspect to them each level will give their stats a little boost aswell as unlock new weapons.


As you can see in this visualsheet the player selects the knight class. Its a close range fighter with high defense and the player is level 10 so he has some experience playing with this class when he loads he'll have the same base stats as a level 10 knight. The other classes also have their speciality written the wizard has long range and high damage with the player level being level 7. The archer class is also range with medium defense and the player level is 15.
When pressing a button you will place down a "ping" that is an object with a picture that will show certain emotes or events that are happing such as a warning sign to other players that the castle is under attack or that the player needs healing. see the image below for a preview of the ping menu.

and when the ping is placed down it looks like this:

Made by: Daan

The first iteration of the enemy system was functional, however it was buggy and didn’t allow for any enemy variation. Therefore we decided to make a 2nd iteration. This system had its movement, targeting and attacking divided into 3 separate scripts, and was altered to use the universal weapon system. This new enemy system allowed for ranged and melee enemies to be made using the same scripts, and also added the ability to select what objects the enemy should target (In case we wanted an enemy that only focused on the base instead of the player, or vice versa). The enemy still used Unity's navmesh system for their pathfinding as this was the quickest and easiest way to do it.
This flowchart describes the enemy's intended behaviour

Made by Byron
We want the player do have different type of playstyles. Classes will have different weapons depending on their type, ranged or close range for example. Classes have a progression aspect to them each level will give their stats a little boost aswell as unlock new weapons. We believed it would be fun to have different ways of defending the base.
The EnemyMovement script is where the scripts communicate with the NavMeshAgent component to tell the enemy where and when to move. The SetTarget function is used to communicate the current target to the NavMeshAgent. In the Update function the script checks wether or not it has reached its set stopDistance from the target. When it has the CheckLineOfSight function will start to be called, this checks if there are any obstacles between the enemy and the player, if there are the enemy will continue to move towards the player. If the enemy is within its stopping distance and has line of sight to the player the StopMove coroutine is called. This coroutine stops the player after a delay, otherwise ranged enemies would often stop halfway behind a wall and shoot it instead. When the enemy is stopped the FaceTarget will quickly lerp the enemy rotation towards the target, and keep doing so untill the target leaves its stopping distance/line of sight.
The EnemyTargeting is where the target for the enemy is determined. On start the ResetTargetToMainBase is called so that the enemy will always spawn with a target. The DetectPlayers function uses an OverlapSphere to check if any players are close, and there are, will call the SetNearestPlayerAsTarget function with the player as a parameter. If the function stops detecting players ResetTargetToMainBase is also called. SetNearestPlayerAsTarget First checks to see if there are multiple players nearby. If there is only a single player then that player will be set as the _enemyTarget. If there are multiple players in range, the function will instead check which is the closest and set that as the target. The UpdateTarget function is required for the navemesh agent to follow its target if it moves as they do not do so by default. UpdateTarget simply communicates the current target's position to the navemesh agent every few frames, and also calls the GetTargetEdge function beforehand. GetTargetEdge will get the closest edge of the target's hitbox instead of its center so that the enemy doesn't end up walking against the target and doing nothing. GetTargetEdge then sets the enemy's target to the calculated position.
The EnemyAttack script does not do a lot by itself, but is made to work with the universal weapon system. The Start function calls the SpawnWeapon function on the weapon ScriptableObject thats given to the script to initialize the weapon. The Attack function calls the attack function on the scriptable object aswell.

The EnemyReferences script simply holds a few references that are required in more than one script to avoid having to do this for each script individually.

In this game we wanted to handle the attacking using weapons. This was so that the same system could be used for all things that needed to attack, and so that all those things needed a single attack script. We wanted these weapons to be easily adjustable and make it easy to add more of them. For this reason I decided to use Unity's ScriptableObjects. This way we could make a weapon in a few clicks and easily drag and drop them onto whatever we wanted. The Weapon parent class has all the necessary functions and variables that the scripts using the weapon need to interact with. Then I made the RangedWeapon and MeleeWeapon classes that inherit from Weapon.

This is the parent ScriptableObject class from which all weapon classes inherit.
The SpawnWeapon function instantiates the model and sets its position to the parent given to the script. DespawnWeapon destroys the model. Attack is to be defined in the classes that inherit from this class, it is defined here so that an Attack script can call the Attack function on every kind of weapon without having to change the script. SetAttackDirection sets the position where the weapon attack should be done and also sets its direction towards the mouse position.
public abstract class Weapon : ScriptableObject
{
[Header("Weapon stats")]
[SerializeField] protected int damage;
[SerializeField] public float attackDelay;
[Header("Visuals")]
[SerializeField] protected GameObject weaponModel;
public GameObject hitboxHolder;
protected Vector3 p_attackSpawnPosition;
protected Quaternion p_attackDirection;
protected GameObject p_model;
public virtual void SpawnWeapon(Transform parent)
{
p_model = Instantiate(weaponModel);
p_model.gameObject.transform.SetParent(parent);
p_model.transform.position = parent.transform.position;
p_model.transform.rotation = parent.transform.rotation;
}
public virtual void DespawnWeapon()
{
Destroy(p_model);
}
public abstract void Attack();
public void setAttackDirection(Quaternion dir, Vector3 pos)
{
p_attackDirection = dir;
p_attackSpawnPosition = pos;
}
}The RangedWeapon class inherits from the Weapon class. The only thing this class changes is that it adds a projectile variable and that it overrides the Attack function to instantiate the projectile in the attack direction.
public class RangedWeapon : Weapon
{
[Header("Projectile settings")]
[SerializeField] private GameObject projectile;
public override void Attack()
{
Instantiate(projectile, p_attackSpawnPosition , p_attackDirection);
}
}The MeleeWeapon class is a little more complicated. It overrides the SpawnWeapon function to additionally spawn a Collider for the melee attack and also to apply a script to that collider that handles dealing damage. DespawnWeapon also additionally destroys those two components. In the Attack function I wanted to use an Coroutine to toggle the collider, however I quickly realised that this is impossible in this script itself as that requires Monobehaviour. To get around this is I made a simple script called WeaponMonoInstance that I would use to handle this coroutine instead. The ToggleHitbox function simply toggles the hitbox on and off.
public class MeleeWeapon : Weapon
{
[Header("Hitbox Settings")]
[Tooltip("The amount of time the hitbox should be active")]
[SerializeField] private float hitBoxDuration = 0.1f;
[Tooltip("How far the hitbox should be placed in front of the player")]
[SerializeField] private float hitboxOffset = 1;
[SerializeField] private Vector3 hitboxScale = new Vector3(1, 1, 1);
private BoxCollider _hitbox;
private WeaponMonoInstance _monoInstance;
private DealDamageOnCollision _damageScript;
public override void Attack()
{
if (WeaponMonoInstance.instance != null)
WeaponMonoInstance.instance.StartCoroutine(ToggleHitbox());
}
private IEnumerator ToggleHitbox()
{
if(_hitbox != null)
_hitbox.enabled = true;
yield return new WaitForSeconds(hitBoxDuration);
if(_hitbox != null)
_hitbox.enabled = false;
}
public override void SpawnWeapon(Transform parent)
{
base.SpawnWeapon(parent);
_damageScript = hitboxHolder.AddComponent<DealDamageOnCollision>();
_hitbox = hitboxHolder.AddComponent<BoxCollider>();
_damageScript.SetDamage(damage);
_hitbox.size = hitboxScale;
_hitbox.center = new Vector3( 0, 0, hitboxOffset);
_hitbox.isTrigger = true;
_hitbox.enabled = false;
}
public override void DespawnWeapon()
{
base.DespawnWeapon();
Destroy(_hitbox);
Destroy(_damageScript);
}
}The attack scripts are all very similar. In the Start function they call the SpawnWeapon function on from the weapon given to the script and give it a spawnPoint. The Update function is where the attack function is called depending on either input for the player or a condition for enemies. There is also a timer that ticks down in Update. the Attack function in all of these scripts first checks to see if the _attackTimer is zero. If it is zero then it will first call the weapon's SetAttackDireciton function, and after it will call the weapon's Attack function. It will then set the _attackTimer equal to the weapon's attackDelay value.