School project / Fall 2024 and fall 2025
Missile and zombie AI in Unity
Game AI assignments in Unity and C#.

Both are built on simple rules for turning, avoiding walls and switching behaviour at set distances.
For my Artificial Intelligence course I made a 2D game where you fire a missile and it chases a moving plane, steering around walls. It can only turn so fast, so it curves toward the plane. For another course I made a zombie that patrols, chases you when you get close, and attacks.
- Wrote the missile. Each frame it turns toward the plane by a limited amount and keeps flying forward.
- Made it look ahead with two lines and steer away from walls before it hits them.
- Wrote the plane that flies back and forth, with a health bar.
- Wrote the game manager, which keeps score and spawns a faster, tougher plane after each kill.
- Added the launcher, the menus, the sounds and the explosions.
- Made the zombie switch between patrolling, chasing and attacking depending on how close you are.
Turning speed
The missile has a top turning speed. Each frame it turns toward the target by no more than that, so it flies in an arc.
Avoiding walls
Two lines point forward from the sides of the missile. If one hits a wall, the missile turns away and slides along it.
The zombie
It chases you within 10 units and attacks within 2, but only gives up past 15, so it doesn't keep switching between patrolling and chasing.
Code I wrote
Short parts of my own code from this project. I left out anything the course gave us.
Missile steering
Missile.cs, Unity C#
void Update()
{
// ...
float dt = Time.deltaTime;
Vector3 desired = _target ? (_target.position - transform.position).normalized : _forward;
Vector3 steerDir = BlendWithAvoidance(desired).normalized;
float maxRad = maxAngularSpeedDeg * Mathf.Deg2Rad * dt;
_forward = Vector3.RotateTowards(_forward, steerDir, maxRad, 1f).normalized;
transform.position += _forward * speed * dt;
transform.up = _forward;
}
// ...
Vector3 BlendWithAvoidance(Vector3 goalDir)
{
Vector3 right = new Vector3(-_forward.y, _forward.x, 0f);
Vector3 left = -right;
Vector3 oR = transform.position + right * rayOffset;
Vector3 oL = transform.position + left * rayOffset;
RaycastHit2D hitR = Physics2D.Raycast(oR, _forward, rayLength, wallMask);
RaycastHit2D hitL = Physics2D.Raycast(oL, _forward, rayLength, wallMask);
// ...
Vector3 blended = goalDir;
if (hitR.collider || hitL.collider)
{
Vector3 n = ChooseCloserNormal(hitR, hitL);
Vector3 t = new Vector3(-n.y, n.x, 0f);
if (Vector3.Dot(t, goalDir) < 0f) t = -t;
blended = goalDir * (1f - normalInfluence) + n * normalInfluence + t * tangentNudge;
return blended.normalized;
}
// ...
}
Zombie states
Enemy_Zombie.cs, Unity C#
void Update()
{
switch (currentState)
{
case State.Patrol:
AvoidObstacles();
Patrol();
if (Vector3.Distance(transform.position, player.position) <= chaseDistance)
{
currentState = State.Chase;
}
break;
case State.Chase:
AvoidObstacles();
ChasePlayer();
if (Vector3.Distance(transform.position, player.position) <= stopDistance)
{
currentState = State.Attack;
}
else if (Vector3.Distance(transform.position, player.position) > returnDistance)
{
currentState = State.Patrol;
}
break;
case State.Attack:
Attack();
if (Vector3.Distance(transform.position, player.position) > stopDistance)
{
currentState = State.Chase;
}
break;
}
}
The missile, plane and game manager scripts came empty with the assignment. I wrote the code in them.
Next school project
Escape Market
Our first full Unreal game, made with Parth Sharma.