Jump to content
  • entries
    940
  • comments
    5,894
  • views
    863,976

ZombieTime


Josh

5,340 views

 Share

AI is always a fun programming topic, and it's even more fun when you're mixing a physics-based character controller with dynamic navmesh pathfinding.

 

We planned on using navmesh pathfinding from the very start of the design of the new engine. Because it was integrated from the very beginning our implementation works really nicely. Pathfinding is completely automatic and dynamic. There are no commands you need to call to make it work. When part of the scene changes, the navigation data for that sector is automatically recalculated. If you haven't seen it already, you can check out some videos on the Leadwerks YouTube channel:

 

Character controllers are a special physics body used to control the movement of characters in the game. They are used for both players as a control method, and by enemies and NPCs. Sometimes they will be controlled by keyboard or touch input, and sometimes they are controlled by AI navigation. Consequently, the character controller class has to be able to handle both.

 

There are so many cool things I can do that it's fun and a little scary. Right now I am toying with the following API. The first two commands would just make the character constantly move to the position or follow the entity you specify, so there's only need to call them once, and the engine will handle the rest:

bool CharacterController::GoToPoint(const float& x, const float& y, const float& z)
bool CharacterController::Follow(Entity* entity)
void CharacterController::Stop()

 

And then you still have manual controls, which are analogous to "UpdateController" from LE2:

CharacterController::SetInput(const float& angle, const float& movement, const float& strafe...)

 

In the screenshot below, I control the rightmost character with the keyboard, while the others are programmed to follow me:

blogentry-1-0-17230600-1341536583_thumb.png

 Share

23 Comments


Recommended Comments

Nice to see GoToPoint and Follow methods. When the framerate drops in LE2 moving to a location using the controller, it would often miss the point and end up rubberbanding back and forth, so hoping this doesn't do that.

 

I said it before but I'll say it again, we should see a bunch of tower defense games spring up quickly with this feature alone. :)

Link to comment

A cool feature in the future would be to add a zig-zag running mode like the zombies in Left 4 Dead. I'm sure it can be done.

Link to comment

And what's cool is that you could just overload GoToPoint() & Follow() to add some kind of value that defines how extreme this zigzag is!

Link to comment

And what's cool is that you could just overload GoToPoint() & Follow() to add some kind of value that defines how extreme this zigzag is!

Yeah, that's what I was thinking.

Link to comment
we should see a bunch of tower defense games spring up quickly with this feature alone

Yeah, but can the navigation system distinguish between road texture and grass texture? tongue.png

 

Also, what would happen if a user clicked a unit to go to a location but that location was not "traversable?" Like a tree or something. Will the unit go to the closest location or not do anything? Better yet, can we choose that navigation mode? Is there an IsLocationTraversable function? Or better still, bool CanTraverseFromLocationToLocation(Vec 3, Vec3)?

 

Regardless, this is all very impressive and easily one of the top features I'm looking forward to in LE3.

Link to comment

As I'm currently trying to achieve some AI-Pathfinding on on LE2, this make me hate the fact that I don't have LE3 already.... Awesome Josh.

Link to comment

This is awesome, maybe consider having a Flee() from target aswell (in all directions or back the way they came.

Link to comment

This is probably the one thing I am most excited about for LE3D. I'm actually trying to create a simple GoToPoint() functions on my character controllers in my game. However, as it stands it is just line of site and at best it will be node based path finding. Just don't have the time to figure out / learn how to do the full thing so this feature will be flipping awesome.

Link to comment

Josh you should try alpha funding with LE3D. Collect money now, give us LE3D now, and do many releases until it's ready. People buying in now would sign off on something agreeing that they understand this is an alpha release. That's becoming a pretty popular path and it helps developers get some money while they work on the final product. Maybe even only allow certain people if you want.

  • Upvote 1
Link to comment

I don't need money right now. Even if I tried hiring more coders, they would only slow things down at this point.

  • Upvote 1
Link to comment

This is indeed coool, Josh! :)

I was wondering...is it possible to set the pathfollowing different per entity? In the vid, all the enemies follow the same path, so is it possible to have them follow different paths individually, and if so, is it hard to do? Does it require new code to make it happen?

 

Cheers

Link to comment

Yeah, that would be nice too. GoToPointUsingSecondBestOption, GoToPointUsingThirdBestOption, etc. GoToPointUsingRandomOption. But I have a feeling the system gives you only one path.

Link to comment
I was wondering...is it possible to set the pathfollowing different per entity? In the vid, all the enemies follow the same path, so is it possible to have them follow different paths individually, and if so, is it hard to do? Does it require new code to make it happen?

Normally your enemies would be scattered around the scene and attacking you from different angles. One technique in Left 4 Dead is to run into an area, shoot a few zombies, then retreat so they all come running at you from one direction, and are easier to shoot. So I'm not sure that behavior is a bad thing.

Link to comment

Is this a form of A* path finding?

 

Does the nav mesh act as a grid? Would this work on a sphere? Having objects navigate the outer side of the sphere?

 

You're tickling my curiousity

Link to comment
One technique in Left 4 Dead is to run into an area, shoot a few zombies, then retreat so they all come running at you from one direction, and are easier to shoot. So I'm not sure that behavior is a bad thing.

I would argue that that's an exploit of dumb A.I. Fine for zombies but how about some smarter enemies? Did you ever hear the phrase "split up" from bad guys in movies?

Link to comment

True, but I think at that point you are getting into more advanced AI that can't be easily automated. You might have a few waypoints set up throughout the scene the enemies know to go to, and then just use the pathfinding to steer them around. There's a lot of ways to make them behave, which makes it a lot of fun to work with.

Link to comment

The problem with functions like GoToPointUsingSecondBestOption() is that there can be literally hundreds if not thousands of options when pathing to a point. As a human you'd look at very out of the way options as a second path, but pathfinding code would maybe move 1 poly on the grid down from the best path and then go to the point. That would be the second best option as far as A* is concerned. This would not result in splitting up behavior.

 

To get what you want would be more AI code than pathfinding code. If the enemy wants to split up and chase the player, then the AI code would instruct the enemy to go certain points way out of the way but with a certain destination in mind giving the illusion of splitting up. This would be your AI logic telling where the controller needs to go then the pathfinding code would get you there.

 

What would be cool around that is to give an array of points to the MoveTo() that the controllers path from point to point in the array.

 

Other cool stuff would be if we could register callbacks that fire when the controller reaches the move to location(s) so we can easily tell when it's reached it's goal so we can then do something else.

Link to comment
Other cool stuff would be if we could register callbacks that fire when the controller reaches the move to location(s) so we can easily tell when it's reached it's goal so we can then do something else.

 

I was actually thinking the same thing. This would be cool. eg. in a stealth game an enemy hears a sound, paths to where he thinks the sound came from and then look around or something like that.

Link to comment

That's how I did the AI in Metal. They went to the position they last saw you, and if they had a clear line of site to see you before they got there, their target destination was updated.

Link to comment

I'm currently working on AI that does just that, moves the agent to the last point you are aware of enemy activity, from whatever sensory input, and then instigates a search pattern if no line of sight contact is made. It will systematically check out likely cover points and literally hunt you down. The search pattern can be split between multiple NPCs. I'm hoping to evolve it to the point where cover is provided by the searching agents whilst a lead agent investigates likely hiding places.

 

I want intelligent looking AI in my game to really challenge people without being impossible to defeat, and that's a challenge in itself.

Link to comment

Nice work Josh. A couple of people in this thread have asked for more advanced usage and I think all this boils down to one broad question: How exposed is the path finding module to the developer?

Do you think more exposure is required in your opinion?

Link to comment

Nice work Josh. A couple of people in this thread have asked for more advanced usage and I think all this boils down to one broad question: How exposed is the path finding module to the developer?

Do you think more exposure is required in your opinion?

It's best to let the navmesh system handle the character movement for AI, because it will calculate avoidance with other characters. If you just plot a path and move there, it won't calculate crowd avoidance.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...