Skip to content

SoldierWrapper

Samuel Arminana edited this page Mar 21, 2017 · 5 revisions

Soldier Wrapper

The Soldier Wrapper class is the Base class that your bot class will inherit from. This class contains essential movements such as moving and interacting.

Set Name

void SetName(string soldierName)

Your bot class should call this method upon Awake. soldierName is the name your bots will be given.

Enemy Spawn Location and Spawn Location

Vector3 enemySpawnLocation

enemySpawnLocation is the center of the spawn box for the enemy team. It is also the location of the enemy flag if it is untouched.

Vector3 spawnLocation

spawnLocation is the center of the spawn box for the team of this bot. It is also the location of the team flag if it is untouched.

Soldiers In Sight

List<IAgent> soldierInSight

soldierInSight is a list that is dynamically populated with any Agents within the view of our bot, whether they be on the enemy team or not.

Warning: The list is not sorted based on any properties.

Flags In Sight

List<IGrabable> flagsInSight

flagsInSight is a list that is dynamically populated with any flags within the view of our bot, whether they belong to the enemy team or not.

All flags are grabbed automatically as long as they are visible, belong to the enemy team, and are within range.

Warning: The list is not sorted based on any properties.

Get Team Soldiers

List<SoldierWrapper> GetTeamSoldiers()

Returns a list of soldiers on your team.

Raycast

RaycastHit Raycast(Vector3 direction)

RaycastHit Raycast(Vector3 direction, float length)

RaycastHit Raycast(Vector3 direction, float length, LayerMask layerMask)

Casts a ray in the direction from the soldier. Returns a RaycastHit.transform null if the direction is out of the view cone, or if no object is hit.

Checking hit

if(Raycast(Vector3.forward).transform)

Shoot

void Shoot()

Calls the shoot method on the weapon class on the gun object.

Look At

bool LookAt(Vector3 position)

position is the position the soldier will look at.

bool response is true if we are within 0.5 degrees of the position. Useful for checking if we are aiming at the enemy we spotted or not.

Move

void Move(Vector3 direction)

Changes velocity to match the direction. The Vector3 will not be oriented to the bot, a direction with z = 1 will move the bot on the z axis no matter it's rotation.

Move Towards

void MoveTowards(Vector3 position)

Calls the Move method and subtracts the position by the transform.position to get a direction.

Grab Flag

void GrabFlag(IGrabable flag)

Happen to have a reference to a flag? Flags are automatically grabbed so this is not necessary for many cases.

Damage Callback

virtual DamageCallback(Vector3 location)

location is the location of the soldier who hit you was when the bullet was fired.

Your bot class can override the method and use the location to its advantage.

public override void DamageCallback(Vector3 location) { }

Flag Status Changed Callback

virtual FlagStatusChangedCallback(IGrabable flag)

flag is the flag that was affected.

This callback is called whether the flag is on your team or the other team and is called when the flag's state has been changed, such as being dropped or grabbed.

Your bot class can override the method and access the flag's interface.

public override void FlagStatusChangedCallback(IGrabable flag) { }

Soldier Died Callback

virtual SoldierDiedCallback(IAgent agent)

agent is the agent that was affected.

This callback is called whether the agent is on your team or the other team.

Your bot class can override the method and access the agent's interface.

public override void SoldierDiedCallback(IAgent agent) { }