Introduction
In this project, we were given the opportunity to create a game, and it could essentially be anything we could imagine. However, there were three specific requirements. These were: the game had to have an over-the-top Christmas theme, it had to be controllable with a controller, and it had to be playable by two people.
I worked on this game with two other classmates who were also close friends of mine. We were able to choose our own teams for this project, and we really went all out!The Making of Christmas Fight
Respawning:
I had to implement a respawn system for when the player dies, but since the game is a 1v1 match in a relatively small map, I didn't want to have just one spawn point in the game. That would allow the opponent to continuously spawn-kill you, which wouldn't be fun. So, I created a system that checks for the farthest spawn point from a list of spawn points that you can configure yourself.
for (int i = 0; i < _respawnPoints.Count; i++)
{
Vector3 playerPos = transform.position;
if (Vector3.Distance(_furthestPoint.position, playerPos) > Vector3.Distance(_respawnPoints[i].position, playerPos))
{
_biggestDistance = Vector3.Distance(_furthestPoint.position, playerPos);
}
else
{
_biggestDistance = Vector3.Distance(_respawnPoints[i].position, playerPos);
_furthestPoint = _respawnPoints[i];
}
}
As you can see in the code, the farthest position, also known as _furthestPoint, is now being set to the farthest respawn point. So, all I need to do now is teleport the player to the _furthestPoint variable when they die.
In hindsight, a better approach would be to calculate the farthest point only when the player dies, rather than every frame as I am currently doing.
Weapons:
So far, there are 4 weapons in the game, and they all share one common feature, which is that they can all attack using the left mouse button. This allowed me to easily create a code that handles weapon attacks. I gave all the weapon animators the same name for the "fire" boolean so that the script works for each weapon.
public class WeaponAttack : MonoBehaviour
{
public Animator WeaponAnimator;
private void OnFire()
{
if (WeaponAnimator)
{
WeaponAnimator.SetBool("Fire", true);
Invoke("SetFireFalse", 0.5f);
}
}
private void SetFireFalse()
{
if (WeaponAnimator.GetBool("Fire"))
{
WeaponAnimator.SetBool("Fire", false);
}
}
}
I can easily use this script for future weapons that need to be able to attack.
In this game, you can also pick up weapons and switch from one to another. So, I made a weapon manager script with a variable that checks all the currently unlocked weapons. To pick up a weapon, I just check if the weapon hasn't been picked up yet and then add it to the 'unlockedWeapon' variable. For weapon switching, I simply activate the new weapon and deactivate the current one.
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
WeaponManager weaponManager = other.GetComponentInParent<WeaponManager>();
for (int i = 0; i < weaponManager._unlockedWeapons.Count; i++)
{
if (weaponManager._unlockedWeapons[i] == weaponManager._allWeapons[weaponUnlock].GetComponent<Animator>()) return;
}
weaponManager._unlockedWeapons.Add(weaponManager._allWeapons[weaponUnlock].GetComponent<Animator>());
//Makes sure the present gets detroyed if picked up.
GetComponentInParent<DropPresent>().PickedUpObject();
Destroy(gameObject);
}
}
Health system:
I also created a health system for this game, but it is almost exactly the same system that I use in my Boulder Brawl game, which you can see here.