Project Brawl
Game Info:
Roles: Game Programmer
Date: Oct 2020
Time: 2 Weeks
Team Size: 5 People (3 Programmers, 2 2D artists)
Genre: Deathmatch
Engine: Unity 3d
Version Control: Perforce
Code Language: C#
Project Brawl is a fighting game that’s mainly inspired by the game Super Smash Bros by Nintendo. The goal is to knock out all other players and be the last one standing.
Challenge: Create a game inspired by at least two arcade games. (We chose to get character inspiration from classic arcade characters / games such as Pong, Pacman and Bubble Bobble)
My Contributions:
Camera System
Having between two to four players where anyone could be dead at anytime was challenging when it came to the camera. We wanted the camera to zoom in on the action when everyone was at the same place as well as zooming out if everyone was spread out. To achieve this I looked at the camera system in Super Smash Bros and wanted to do something similar. Unity had a very helpful Bounds object to achieve this and I just had to keep track on current alive characters.
The current alive players was held in the PlayerManager class and this added and removed the character to the cameratarget lists as wanted.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
[RequireComponent(typeof(Camera))]
public class MainCamera : MonoBehaviour
{
#region Editor variables
[Header("Camera zoom settings")]
[SerializeField] private float minZoom = 2f;
[SerializeField] private float maxZoom = 40f;
[SerializeField] private float zoomLimiter = 1f;
[Header("Camera movement settings")]
[SerializeField] private float smoothTime = 0.5f;
[SerializeField] private Vector3 cameraOffset;
[SerializeField] private float minYPos = -13f;
#endregion Editor variables
#region Unity Objects
private Vector3 velocity;
private Camera cam;
#endregion Unity Objects
#region Property varables
public List<Transform> CameraTargets { get; set; }
#endregion Property variables
#region Unity functions
private void Awake()
{
CameraTargets = new List<Transform>();
cam = GetComponent<Camera>();
Assert.IsNotNull(cam, "Could not find camera component on main camera.");
}
private void LateUpdate()
{
if(CameraTargets.Count == 0)
{
return;
}
Move();
Zoom();
}
#endregion Unity functions
#region Camera movement
private void Move()
{
Vector3 centerPoint = GetCenterPoint();
Vector3 newPosition = centerPoint + cameraOffset;
if(newPosition.y < minYPos)
{
newPosition.y = minYPos;
}
newPosition = new Vector3(newPosition.x, newPosition.y, transform.position.z);
transform.position = Vector3.SmoothDamp(transform.position, newPosition, ref velocity, smoothTime);
}
private void Zoom()
{
float newZoom = Mathf.Clamp(GetGreatestDistance(), minZoom, maxZoom);
cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, newZoom, Time.deltaTime);
}
#endregion Camera movement
#region Calculations
private Vector3 GetCenterPoint()
{
if(CameraTargets.Count == 1)
{
return CameraTargets[0].position;
}
Bounds bounds = new Bounds(CameraTargets[0].position, Vector3.zero);
foreach (Transform target in CameraTargets)
{
bounds.Encapsulate(target.position);
}
return bounds.center;
}
private float GetGreatestDistance()
{
Bounds bounds = new Bounds(CameraTargets[0].position, Vector3.zero);
foreach (Transform target in CameraTargets)
{
bounds.Encapsulate(target.position);
}
if (bounds.size.x > bounds.size.y)
{
return bounds.size.x;
}
else
{
return bounds.size.y;
}
}
#endregion Calculations
}