Inspired by the game Gladiabots
This project provides a platform to build AI controlled ships that battle to the death! There is support for upto 4 teams currently
A live Demo of the project can be seen here
- Unity Game Developement Engine
- Visual Studio 2015 *VS allows for the use of the debugger"
Unity Tutorial (I had actually found the spaceship sprites before I saw the tutorial =) )
Be sure to clone the Repo and open the Unity project to get started
When you get the project open, be sure to click on "Scene1" in the projects tab at the bottom
The files you will be changing are /Assets/Scripts/AI_Blue.cs or /Assets/Scripts/AI_Orange.cs
Each file represents the AI for the corresponding team
- A maximum of 1.0 unit of movement can be applied per frame
- A maximum of 1.0 unit of rotation can be applied per frame
- Bullets lose damage over time (Damage halved every 2 seconds (exponential decay))
- Fire rate is decreased linearly with the ship's speed (25% slower fire rate at 100% movement speed)
- ID can be used to give bots unique behaviors
These are read only
int ID
float Health
int MaxHealth
float Shield
int MaxShield
float ShieldChargeRate
int ShieldChargeDelay
int ShieldChargeTimer
float ShotDamage
float ShotSpeed
int ShotDelay
int ShotTimer
Vector2 Force
float ForceScale
float Turn
float TurnScale
float ArenaWidth
float ArenaHeight
float Radius
float X
float Y
Vector2 Position
Vector2 Velocity
float Direction
bool Shoot();
// Fires in the current direction, 'ShotDelay' is the number of frames between shots
// Returns true if bullet was fired that frame, false otherwise
bool ShootAt( BotAI bot , float rotationSpeed = 1f );
// Will turn towards 'bot' and Shoot, returns false if bot does not exist, true otherwise
void ShootAt( Vector2 pos , float rotationSpeed = 1f );
void ShootAt( float x , float y , float rotationSpeed = 1f );
float DistanceToBot( BotAI bot );
// Returns the distance to 'bot'
// Returns INF if 'bot' does not exist
float DirectionToBot( BotAI bot );
// Returns the direction in degree to 'bot'
// Returns INF if 'bot' does not exist
// For the following rotate and move functions 'speed' should be given in the range of -1.0f to 1.0f
void RotateLeft( float speed );
void RotateRight( float speed );
void Rotate( float speed );
// CCW is positive speed
void RotateBy( float angle , float speed );
// NOT IMPLEMENTED
bool RotateTowards( BotAI bot , float speed = 1.0f );
// Returns false if bot does not exist, true otherwise
void RotateTowards( float direction , float speed = 1.0f );
// Rotates the ship to match the given 'direction', 0° is to the right and goes CCW
void RotateTowards( float x , float y , float turnSpeed );
RotateTowards( Vector2 pos , float turnSpeed = 1.0f );
void MoveForward( float speed = 1.0f );
// Using a negative 'speed' as the same as using MoveBackward with positive 'speed'
void MoveBackward( float speed = 1.0f );
void MoveRight( float speed = 1.0f );
void MoveLeft( float speed = 1.0f );
bool MoveToward( BotAI bot , float speed = 1f , float turnSpeed = 1f );
// Turns towards and moves towards 'bot'. Returns false if bot does not exist, true otherwise
void MoveToward( float direction , float speed = 1f , float turnSpeed = 1f );
void MoveToward( Vector2 pos , float speed = 1f , float turnSpeed = 1f );
void MoveToward( float x , float y , float speed , float turnSpeed );
BotAI[] FindBots();
// Returns an array of all bots
BotAI[] FindEnemies();
// Returns an array of all enemies
BotAI[] FindAllies();
// Returns an array of all allies
// Any of the following superlatives can be used in place of "Superlative" for the 3 functions below
/*
Closest // will not return itself
Furthest // will not return itself
Strongest // Health + Shield
Weakest // Health + Shield
HighestHealth
LowestHealth
HighestShield
LowestShield
*/
// ex. FindLowestHealthEnemy()
BotAI FindSuperlativeBot();
//returns null if no such bot exists
BotAI FindSuperlativeEnemy();
//returns null if no such bot exists
BotAI FindSuperlativeAlly();
//returns null if no such bot exists
A simple AI file will look like this
using UnityEngine;
using System.Collections;
public static class AI_BlueTeamSettings
{
public const string TEAM_NAME = "BLUE"; // Be sure to five your AI a name
public const string AUTHOR = "";
public const string VERSION = "0.0";
}
public class AI_Blue : BotAI
{
// Initialize class variables here
// This is will most of the AI logic will go
// It is called once per frame
void AI_Routine()
{
// Example
BotAI enemy = FindWeakestEnemy();
if ( enemy != null )
{
if ( ID <= 2 )
{
MoveRight( 1.5f );
}
else
{
MoveForward( .5f );
}
ShootAt( enemy );
}
// End Example
}
// DO NOT MODIFY THIS FUNCTION
new void FixedUpdate()
{
if ( Game.GameStart )
{
AI_Routine();
base.FixedUpdate();
}
}
}
- option1 (preferred): Create a new branch named "yourname_AI", push to github. Then send me message telling me the name of your branch and which team color I should use.
- option2: send me the file contents of AI_Blue or AI_Orange on slack
v1.0
Add Bot ID'sFix movementAdd UI- Load AI Dynamically
Provide access to arena sizeProvide access to getBots/Enemies/AlliesBalance Bot paramters
v1.1
- Add powerups
- Improve UI
- Add second type of ship