BANANAMAN
Resident Star Battle Expert.
- Reaction score
- 150
I want an AI wherein the object with the AI will initially idle when the game starts,Suddenly wander/move around at random and when the player control object reaches a certain range it begins to chase it.
I was thinking of having the AI have 3 states,Wandering,Chase and Idle where Idle is the default AI. From time to time it will mostly wander around the scene (while switching to idle state depending on a random integer) but then when the player controlled object is within a certain distance from it the AI will switch to chase state.
pesudo-code
Case:idle
//do nothing/play idle animation
status = rand()
if (status <= 0.5)
{
state = wander;
}
break;
Case:wander
//wander around/play wander animation
if ((plyrdist <= AIx) || (plyerdist <= AIy) || (plyrdist <= AIz))
{
state = chase;
}
else
{
status = rand()
if (status <= 0.5)
{
state = wander;
}
if ((status >= 0.5)&&(status <= 0.9))
{
state = idle;
}
}
break;
is there another way that's much more efficient to accomplish this?
I was thinking of having the AI have 3 states,Wandering,Chase and Idle where Idle is the default AI. From time to time it will mostly wander around the scene (while switching to idle state depending on a random integer) but then when the player controlled object is within a certain distance from it the AI will switch to chase state.
pesudo-code
Case:idle
//do nothing/play idle animation
status = rand()
if (status <= 0.5)
{
state = wander;
}
break;
Case:wander
//wander around/play wander animation
if ((plyrdist <= AIx) || (plyerdist <= AIy) || (plyrdist <= AIz))
{
state = chase;
}
else
{
status = rand()
if (status <= 0.5)
{
state = wander;
}
if ((status >= 0.5)&&(status <= 0.9))
{
state = idle;
}
}
break;
is there another way that's much more efficient to accomplish this?