Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411977 Posts in 69438 Topics- by 58486 Members - Latest Member: Fuimus

June 15, 2024, 03:38:04 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)AI move with cover
Pages: [1]
Print
Author Topic: AI move with cover  (Read 1454 times)
deemen
Level 0
***


View Profile WWW
« on: June 16, 2010, 07:03:29 AM »

Hi all,

I've been working on the AI for my game last couple of days and I've been running into problems. I'm quite familiar with pathfinding and A*, and that's very useful when I want an enemy character to chase the player. However it's getting to a point where AIs are simply running down players like Zombies and it's not a very convincing experience.

What I'd like is for the AI to move around while taking into account cover, possibly seeking cover themselves. So far I've resorted to dropping cover nodes all over my A* graph and then raytracing to the player to see if the cover is valid or not. This seems like a really impractical solution though... Do you guys have any suggestions on how to tackle this? My game is a 2D shooter and I want the enemies to behave convincingly.

Dan
Logged

Project Lead - Programmer @ Crankshaft Games
Current Project: Party of Sin
Pineapple
Level 10
*****

~♪


View Profile WWW
« Reply #1 on: June 16, 2010, 07:20:14 AM »

Perhaps determine where on your map of A* nodes are considered cover from the player's fire (via raytracing) and give the nodes covered a lower cost than nodes in the open.
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #2 on: June 16, 2010, 07:40:05 AM »

Isn't this raycasting and not raytracing, or do I have my terms mixed up again?
Logged



What would John Carmack do?
st33d
Guest
« Reply #3 on: June 16, 2010, 08:19:37 AM »

Have you tried scheduling the AI? Those routines don't have to run every single frame, split the load across several. Run only one raycast per frame, you won't notice the difference of only one enemy looking for the player each frame.

Also, I've found this book immensly helpful:

Artificial Intelligence for Games

I'm personally working with a set of emotional states for my monsters, either chasing, fleeing or patrolling. I simply switch between each state and work on the AI for each separately.
Logged
jay
Level 0
***


Spray it, don't say it


View Profile WWW
« Reply #4 on: June 16, 2010, 08:50:36 AM »

Slightly OT, but that book looks excellent, just the kind of thing I was looking for. Thanks for the recommendation.
Logged

slembcke
Level 3
***



View Profile WWW
« Reply #5 on: June 16, 2010, 09:16:18 AM »

I was just thinking about this the other day actually. My thoughts went something like this:
  • Make sure you have plenty of nodes. (if the game is tile based, you should be covered)
  • Each frame (or every several frames) find the nodes within a certain distance of the player and raycast to them. If the raycast hits them mark the node with the current timestamp. If you have multiple points you want to hide from, you can have a counter that increments for each raycast.
  • When searching for a path, multiply the edge weight by a certain factor if the destination node is marked with the current timestamp. (increase the factor based on the counter if you are using one)

By marking nodes with a timestamp, you only need to worry about marking the nodes the raycasts could actually hit. You don't need to clear and raycast every node again. It also allows you to use a spatial index of some sort easily if you have one ready. (presumably you do if you are raycasting or have other collisions.)

If raycasts are really expensive in your engine, you could add a cone of vision and simply reject nodes that are not in the cone using a simple dot product. This would probably work Ok in a 3D game where the player has a limited cone of vision, but not so much in a 2D game or a 3rd person game.
Logged

Scott - Howling Moon Software Chipmunk Physics Library - A fast and lightweight 2D physics engine.
deemen
Level 0
***


View Profile WWW
« Reply #6 on: June 16, 2010, 10:34:52 AM »

Have you tried scheduling the AI? Those routines don't have to run every single frame, split the load across several. Run only one raycast per frame, you won't notice the difference of only one enemy looking for the player each frame.

Also, I've found this book immensly helpful:

Artificial Intelligence for Games

I'm personally working with a set of emotional states for my monsters, either chasing, fleeing or patrolling. I simply switch between each state and work on the AI for each separately.

Thanks for the link. Very insightful. I'll see if I can pickup a copy of that one.

Update: AI book on it's way. I'm getting so broke hah
« Last Edit: June 16, 2010, 01:54:38 PM by deemen » Logged

Project Lead - Programmer @ Crankshaft Games
Current Project: Party of Sin
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #7 on: June 16, 2010, 02:44:23 PM »

Just do tons of ray casts. Raycasts should be cheap, and you could spend your time fixing that up instead of trying to work around it.
If you still need more power, consider splitting the area up into connected subareas with visibility information  when making the map, and using this to cut down on visibility determining.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic