Graphics Reference
In-Depth Information
public virtual void NoMove ()
{
vert= 0;
}
The LookAroundFor() function starts out by using a distance check (using Unity's
Vector3.Distance function) to find out whether or not the bot's transform (in myTrans-
form) position is within maxChaseDistance 3D units:
public virtual void LookAroundFor(Transform aTransform)
{
// here we do a quick check to test the distance between AI
// and target. If it's higher than our maxChaseDistance
// variable, we drop out of chase mode and go back to
// patrolling.
if( Vector3.Distance( myTransform.position, aTransform.
position ) < maxChaseDistance )
{
When the target transform is close enough (within maxChaseDistance), the next step
is to find out whether or not it is visible to this bot. The CanSee() function takes care of
this, returning true or false depending on whether the bot “can see” the target transform
or not:
// check to see if the target is visible before
// going into chase mode
if( CanSee( followTarget )==true )
{
At this stage, we know that there is a target within range and that it is visible to this
bot (there are no obstacles between the bot and the target) so we can switch over to AIState.
chasing_target to start the chase:
// set our state to chase the target
SetAIState( AIState.chasing_target );
}
}
}
One of the core components of the AI controller is the IsObstacleAhead() function. In
this part, Physics.Raycast is used to raycast out ahead (and slightly to the left or right) to
check for obstacles. It returns an integer, expressing its findings with the following values:
0
No obstacles were found.
1
An obstacle was detected front, left side only.
2
An obstacle was detected front, right side only.
3
Obstacle or obstacles detected on both sides.
The beginning of the function checks to make sure that we have an actual transform
in myTransform to start with:
private int obstacleFinding;
Search WWH ::




Custom Search