Project Portal

All projects

Tank Bots preview

Experiments · Experiment

Tank Bots

Simple Tank NPCs using FSM's and Dot-Product FOV

Hosted on itch.io. Use the player’s fullscreen control for more room.Open on itch.io ↗

Tanks Bots

THE PROJECT

Tanks Bots (formerly Tanks AI) was a concentrated effort to sophisticate my understanding around finite state machines, and how I can use that to create fun, believable(ish) NPCs for my various game projects.

The end result was a neatly packaged sandbox where the player can spawn 2 types of tanks, across 3 types of teams, and watch them duke it out.

Core Mental Blueprints Extracted:

  • Dot Products are great for FOV
  • FSMs are valuable in many ways
  • Data containers are imperative to manageable content

How it Went

The Brains

I started the project from the back of a Jason Weiman video on finite state machines, effectively mimicked his setup with my own parameters, and mashed it together with Sebastian Lauge's 12+ year old FOV video. Love the internet.

Through Tank Bots, I got my first exposure of some incredibly elementary coding:

  • Creating objects at runtime (I discovered the shocking reality that you can have Classes that aren't mono behaviours)
  • Scriptable Objects as data containers
  • Structs as damage packets (Although I believe I moved this back to classes to keep them mutable for probably no good reason)
  • Changing materials at runtime
  • Trailer Renderer and Nav Mesh

So, we had a brain- now we needed eyes. Que Sebastian.

The Senses

I started with a "ray-fan", which you guessed it, was a fan of that would refresh every physics tick to report if they had collided with a an enemy. I kinda knew straight away that wasn't going to be a good long-term fix. It can't look up, down, and has gaps- so, after some digging I found the Sebastian tutorial.

In short, we use a simple dot-product to say "Anything in this 3d cone, report it to my brain- and if I want to kill it, tell the FSM it's time to kill".

Simple, elegant, and to-this-day remains the basis of "Eyes" in NPCs and pretty much anything that needs conical area- notably: Melee hurt-boxes.

The Movement

Movement is a very short section- the units parse their target transform to the unity Navmesh system, and they move. Magic.

Allegiance

Through Tank Bots, the first iteration of my "Affiliation" system was born; a scriptable object that NPCs would reference to check if they hated or loved the tank in-front of them. It was a useful exercise in lists and dictionaries, and the bones of this system carry in to [[The Never Ending Character Controller]].

One day I might redo this project as a beginner tutorial; it many ways, Tank Bots was really the start of my true belief that I could create the pieces we need to make an engaging loop- all other systems inline with character control and generation were elementary in theory, but now that I had implemented state machines, persistent data containers, NPC Navigation and factions... I had no excuses not to create.

Core Learnings

Through this project, a-lot of important prototypes were crafted. Looking back on this years later, these are the key things I took away, many I added to my ongoing toolkit

  • Finite State Machines - Great foundation for simple NPC behaviour, however the primary thing this taught me (that I didn't even know at the time) was my first real programming pattern.
  • Scriptable Objects - Or more precisely, data containers that survive runtime.
  • Static Methods - Yes, yes... I had no idea how to use them until this project.

Resources: Jason Weimann (FSM) https://www.youtube.com/watch?v=V75hgcsCGOM Sebastian Lague (FOV) https://www.youtube.com/watch?v=73Dc5JTCmKI