• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
gamer_prog

How does ai spot enemies

7 posts in this topic

Hi,

I was wondering, and like as much information on it as possible, how does ai spot enemies in games, FPS for the most?

How does the general idea work, the code and mechanics?

Is it just by a set distance that the ai would automatically "see" you or spot you based on script or game engine (for the obvious reason it cannot actually "see", it has no physical eye)? Or does it generally use a "view cone" or anything such? And how do you combine those elements into a working functioning game or code part or engine part? How does it work down, what steps does it go through or cycle through in order to get the final result "it has spotted an enemy unit"? Something I can work with, that works. Something realistic.



Thanks.
0

Share this post


Link to post
Share on other sites
Ok. So the raycasting is like "pinging" the range or view it is looking at and if there is a unit and nothing blocks it, it will return a potential line of sight?

How do games in general do it, outside of the raycasting as you mentioned? Is this the best way and most common way of doing it?

Is there some example code how to implement this into a game? Not just for raycasting but how ai spots enemies in general.
0

Share this post


Link to post
Share on other sites
Yeah as above, you traditionally use a raycast system. Pick a few points on the target's body (e.g. head, chest, knees) is if those points lie within the AI's view-cone, perform a ray-cast to determine if they're visible.
To make it seem a bit more 'human' you can add lots of little tweaks, such as only triggering a "enemy spotted" event if the ray-casts continue to spot the target for several seconds, etc...

There are other techniques, such as using the GPU to rasterize a depth buffer from the AI's point-of-view and using occlusion queries for it's targets, or performing ray-casts against precomputed depth cube-maps, but that's pretty exotic stuff.
2

Share this post


Link to post
Share on other sites
Ok cool.

Do you have or is example code I can use? Basically to try it out?

And is there any other code, not GPU usage code, that is used for this? Or do all games use raycasting in general? Just to be sure.
-1

Share this post


Link to post
Share on other sites
[quote name='Gamer Sys' timestamp='1303224880' post='4800383']And is there any other code, not GPU usage code, that is used for this? Or do all games use raycasting in general?
[/quote]
Dude... 3 people just told you that games use raycasting for this... why would you ask again? To answer your question about "other ways", though, any solution is going to involve 3D trig and the geometry of the level... something at which the GPU kinda has a pretty good handle on. Rolling your own solution would be sub-optimal in most cases.

As for code, read the docs of whatever graphics library you are using. You will find a set of simple raycast calls -- very likely with examples of how to use it in these situations.


0

Share this post


Link to post
Share on other sites
If its a game in which everything is divided up into a grid or hexes or sectors, then a more efficient way to do the raycasting is just do a cast from the center of the character (agent in question) to each of the mobs within a given radius - no need to do a full LOS raycast as if you were rendering the scene in 3D. You could do additional casts if you wanted a more precise model (like if a mob is 3/4 obscured by a wall, the single cast would not show them as seen, but if you do 3 casts (leftside, center, rightside) then you will see a mob if any part of it sticks out from a wall).

The pseudo-code would be something like this:

for each mob within a given sight radius,
use the Bresenhan line drawing algorithm given the target mob x,y and the seeing mob x,y ([url="http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm"]Bresenham Wiki[/url])
check each grid coordinate the line routine brings up to see if it obscures -> if yes, then unseen
loop until no more mobs in range


Even is your game is not grid based, it is generally much quicker to raycast only the mobs instead of the entire scene since there a generally alot less mobs then general area.

Hope this makes since.

and, of course, I could have misunderstood your question.

Bresenhams line drawing is my favorite and I am very familiar with how to cast both 2-D and 3-D scenes if you need additional help with the coding.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0