Over run Z

The goal of the game is to get the zombies to human so they can eat him. The zombies move in a group and want to be with each other.

As acting team lead, I assigned tasks to the team members and bridged the gap between artists and developers. As developer I coded the zombie movement AI, main camera movement and the human survivor AI.

The zombies move with a Navmesh. If you let go of the controls the zombies flock together. If one zombie is really far from the group it will not get stuck because it knows how to navigate through the room.

The zombies move by path finding to a target. The game calculates the target based on the centre of all the zombies and adds the keyboard input with the camera rotation. The red line (left picture) shows this: the line starts at the centre of the zombies and ends at the target.

public class InputTargetCamera : MonoBehaviour
{
    private Vector3 _centerofZombies;
    [SerializeField] private Vector3 inputPlusCamera;
    [SerializeField] private float angleOfInput;
    [SerializeField] private float cameraRot;

    void Update()
    {
        if(Game_Mannger.Instance.Zombies.Count == 0) return;
        
        // get input
        Vector3 input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        
        // get the Angle of the input
        angleOfInput = (Mathf.Atan2(input.x, input.z));
        // get the camera rotation and make it face to the frond
        cameraRot =  (Camera.main.transform.rotation.eulerAngles.y+90) * Mathf.Deg2Rad;

        // makes sure that the zombie want to go to the survior not past him
        var targetvsSur = (Game_Mannger.Instance.survivor.transform.position - transform.position).magnitude;
        
        // add the input angle and the camera angle to each other. then create a vector from the angles
        inputPlusCamera = new Vector3(
            Mathf.Cos(cameraRot+Mathf.PI + angleOfInput), 0, 
            Mathf.Sin(angleOfInput + cameraRot)).normalized * Mathf.Min(targetvsSur,input.magnitude*10);
        
        // calulate the center of the zombie we know it can't be 0
        _centerofZombies = Vector3.zero;
        foreach (var zomby in Game_Mannger.Instance.Zombies)
        {
            _centerofZombies += zomby.transform.position;
        }
        _centerofZombies /= Game_Mannger.Instance.Zombies.Count;

        // get point on navmesh for zombies
        NavMeshHit hit;
        NavMesh.SamplePosition(_centerofZombies + inputPlusCamera, out hit, 1000, NavMesh.AllAreas);
        
        transform.position = hit.position;
    }

    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawRay(_centerofZombies, inputPlusCamera);
    }
}

This code calculates where the zombies are going to. The hardest part was to combine the camera angle with the keyboard input. It works using Cos and Sin maths. Now the game can rotate the camera without confusing the player with weird keyboard steering controls.

International Team: 2 developers, 3 artists
Type: International School Game Jam

https://ddaengaxy.itch.io/over-run-z
https://itch.io/jam/international-educations-jam/rate/908744
https://github.com/gelearthur/box_and_zombies

2021 Feb 2 – 2021 Feb 5