A NPC (Non-Player Character) is an abstraction of a living being. He/She senses its surroundings [Sense], think about what he/she has sensed [Think] remembering previous events [Memory], and reacts to the stimulus of the world [Do] storing his/her behavior for future reasoning [Feedback]. In the previous lesson we saw (in a very superficial way) how a NPC acts [Do]. Now, it's time to give some hints about how Senses work.
And how vision works for a NPC? Simplifying everything. The main purpose of the vision subsystem is to send to the NPC the entities he/she is viewing at a certain moment of time. How to make that? First, the NPC must create a set of entities he/she is looking at. But this is not made making an "image" of the world. Instead, the NPC just "throw rays" (makes a bresenham algorithm) in all the directions of his/her vision field for a certain length (which can be modified depending on your design decisions). And if the ray "hits" an entity, it's added to the entity list. This can be simplified more, making the NPC to directly try to "throw a ray" into all entities in his/her vision range. And second, the NPC must recognize the entities. But there is no image recognition here. Every entity in the universe has a sort of label (like the "cat" in the figure: "Cat - NPC - ID 2000"), and that label is used for recognizing what is the entity. A final note: If you have played any game of the "Commandos" franchise, you will remember the option of knowing the range of vision of a certain soldier. Now, you can understand a little more how it works (alarm, alarm!!! ^_-).
So, how we can abstract sounds and scents? All sounds and scents have an origin. And both of them can be abstracted into a circle (wave) that grows until the sound wave (or scent fades away). Therefore, in a game, a sound or/and scent can be a circular wave which is generated when an entity makes a sound/propagate an scent. This wave carries some information about the type of sound/scent. And when the limit of the wave hits another entity, that entity receives the information contained in the wave. Also (simplifying things), a sound/scent can be just a "ray" being thrown by the entity who generates it to all entities in the sound/scent range. Another final note: "Commandos" again. Remember the sound wave made by your commandos when you were running? ^_-.
Okay, now a NPC can see, hear, and smell its sorroundings, and can touch and taste. But there is one important sense to develop - the internal state of a NPC. It tells how the NPC feels, both physically and psychologically. If the NPC is hungry (he can try to find food), if the NPC is in danger (just look at the picture - guess the NPC should get out of that place immediately!),... For the physical feelings, you only have to check for changes in the physical statistics of the NPC (e.g. decreasing hit points). For the psycological issues... well, it's more complicated (depends on rules: If the NPC is continously losing HP, he will be veeeery veeeery scared), and i also doesn't know how to manage them properly. So take a look to the work of the professionals: Just search for the postmortem of any game with really cool AI, like "The Sims", "Black and White", and "Fable" ^_-.
|