Warehouse
"Practical wisdom is only learnt in the school of experience." -Samuel Smiles
PROJECTS NEWS MESSAGES MAILING LIST  
AI Game Development
Learn how to create smart creatures in computer games that learn and react to their environment. Neural networks, genetic algorithms, reinforcement learning and more!
More information at Amazon US UK

Reply to Message

Not registered yet?

The AI Depot has a focused community of friendly users. Rather than let anyone abuse the site at the brink of promiscuity, we prefer to let only those with an active interest participate... this simply requires registering.

Why not sign up!

Joining the site's community is completely free. You can then post messages freely, and customise your personal profile at will. Specific privileges will also be granted to you, like being able to access printer-friendly articles without restrictions. So, why not register?

Username:
Password:
Subject:
Email me when someone replies.
Body:

Parent Message

Help Needed in AI in 3D Games

Think I can help you on your way...

For the following, I'm assuming that you are already able to make the enemy walk and turn.

Easiest way I can think of, is using a waypoint system and a state machine.

Waypoint system: You specify locations (waypoints) in your environment (ie. in a level editor), and for each location you specify the connections to other (nearby) waypoints. This way you can create a grid or paths your enemy can walk on. Good thing about this is that you don't have to worry about collision detection (at least not with the static environment)

State machine: Can be implemented as a switch/case statement. You will need about three states: Guard, run, attack...

A short (pseudo code):

switch (currentState)
{
case STATE_GUARD:
{
// Do nothing but standing

// Check whether to change to another state
if (distanceToPlayer < 5.0f)
{
currentState = STATE_ATTACK;
}
}
break;

case STATE_ATTACK:
{
// Shoot gun/use blade/whatever

if (distanceToPlayer < 3.0f)
{
currentState = STATE_RETREAT;
}
}
break;

case STATE_RETREAT:
{
// Shoot gun/use blade/whatever
WalkAway();

// WalkAway should disable state machine until a certain distance (ie > 5.0f)
currentState = STATE_GUARD;
}
break;
}

Note that the above piece of code is missing something trivial: Pathfinding. Easiest is to implement WalkAway something like this.

void WalkAway()
{
for (int i=0;i<currentWaypoint.NumConnections;i++)
{
if (GetDistanceBetween(currentWaypoint, currentWaypoint.Connection[i]) > DistanceToPlayer)
{
// Do your enemy walk code here
WalkToWaypoint(currentWaypoint.Connection[i]);
return;
}
}
}

Hope this makes any sense!

If not, drop me a mail on [email protected]

9 posts.
Monday 14 October, 09:17
Reply

Back to the AI Foundry.