Hello, guys !!!
My head is spinning like a record
and i cannot figure this simple fsm thing.
I cannot decide what type of fsm is represented by the below code
//-- Finite state machine
function AIFSM()
{
switch (state)
{
case chase:
Chase();
break;
case evade:
Evade();
break;
case loadHealth:
LoadHealth();
break;
case loadWeapons:
LoadWeapons();
break;
default:
break;
}
}
function Chase()
{
var enemy = FindClosestEnemy();
NavigateTowardsSpecificWaypoint(Vector3(enemy.transform.position.x+10,enemy.transform.position.y,enemy.transform.position.z+10) );
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
// Bit shift the index of the layer (10) to get a bit mask
var layerMask = 1 << 10;
// This would cast rays only against colliders in layer 10.
// But instead we want to collide against everything except layer 10. The ~ operator does this, it inverts a bitmask.
layerMask =~ layerMask;
// Did we hit anything?
if (Physics.Raycast (Vector3(transform.position.x,transform.position.y,transform.position.z), direction, hit, 100,layerMask))
{
if(hit.collider.tag == "carColliderTag")
{
ammo.EnableAutoFire();
}
else
{
ammo.DisableAutoFire();
}
}
else
{
ammo.DisableAutoFire();
}
if(health.GetHealth() < 35 )
{
state = loadHealth;
}
else if(health.GetReceivingDamage())
{
state = evade;
}
else if(ammo.GetSpeedAmount() + ammo.GetHomingAmount() + ammo.GetPowerAmount() < 3)
{
state = loadWeapons;
}
}
function Evade()
{
ammo.DisableAutoFire();
var RelativeWaypointPosition : Vector3 = transform.InverseTransformPoint( FindClosestEnemy().transform.position );
// by dividing the horizontal position by the magnitude, we get a decimal percentage of the turn angle that we can use to drive the wheels
inputSteer = -RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude;
inputHandbrake = 0;
inputMotor = 1;
inputBrake = 0 ;
if(health.GetHealth() < 35 )
{
state = loadHealth;
}
else if(!health.GetReceivingDamage())
{
state = chase;
}
else if(ammo.GetSpeedAmount() + ammo.GetHomingAmount() + ammo.GetPowerAmount() < 3)
{
state = loadWeapons;
}
}
function LoadHealth()
{
ammo.DisableAutoFire();
NavigateTowardsSpecificWaypoint(FindClosestHealthPack());
if(health.GetHealthTaken())
{
health.SetHealthTaken(false);
if(ammo.GetSpeedAmount() + ammo.GetHomingAmount() + ammo.GetPowerAmount() < 3)
{
state = loadWeapons;
}
else if(health.GetReceivingDamage())
{
state = evade;
}
else
{
state = chase;
}
}
}
function LoadWeapons()
{
ammo.DisableAutoFire();
NavigateTowardsSpecificWaypoint(FindClosestMissilePack()) ;
if(ammo.GetWeaponsTaken())
{
ammo.SetWeaponsTaken(false);
if(health.GetHealth() < 35 )
{
state = loadHealth;
}
else if(health.GetReceivingDamage())
{
state = evade;
}
else
{
state = chase;
}
}
}
i have a book ( AI for game developers David M.Bourg)
and it does not write a single line about moore/mealy machines.