Tuesday, 11 March 2008

Do AI Dream of Electric Llamas?

Subtitle: The Joys of not walking into walls.

I've had a basic -but working- pathfinding routine going which my AI have been slavishly wandering around, happily not walking into things. It's a Dijkstra based script with manually predefined node connections (that C grade in Maths I scraped at school has finally come in handy) where the AI builds a path from it's position to it's goal. It all works fair enough but looks terribly wooden as the AI pull many 90 degree turns in the open, so I've added functionality.

AI Pathfinding Routine:
1: Check that we have a goal - if not chill. Goals are set to named AI at spawn and altered via triggers.
2: Get a vector distance to the goal - if it's under 2 metres we're there. Clear the goal. Thread 1.
3: Check LOS to goal - if it's clear run to it directly (No need to waste precious processor power on it.) Thread2, if not we're gonna have to run Dijkstra to find a path around the obstacles.
4: Build the node list and get moving along it.
5: At every node make an LOS check to the goal
If it's clear make the current node the last in the path and just run to the goal. Thread 2.
If LOS is still blocked by something, move to the next node in the list. Repeat until path complete and Thread 2.

This all makes things look much better, cutting down on the slavish adherence to the path when the goal is clear, and gives a more naturalistic route. I still want to enlarge the AI goal radius (currently 10cm/4 inches which is just daft - when I made my SP campaigns for Call of Duty I never went under 32 inches if I needed them right in a certain places - like a window - and quite often felt 64 was fine) and I need to come up with a team-member-avoidance/onstuck function to stop the AI bumping into each other (a larger goal radius should also help to reduce contacts).

And sorting out some demo-reel footage might be good.

No comments: