Jump to content

  • Log In with Google      Sign In   
  • Create Account






Programming the 5 Senses (entry)

Posted by Tutorial Doctor, 10 January 2014 · 339 views

sense program ai artificial intelligence
This is a re-post from a thread I started. I am posting it here and will update from the journal:

http://www.gamedev.net/topic/651885-programming-the-5-senses/

I need some feedback on something I call a Senses System. Someone said that the way I am doing it is wrong, so I need some suggestions on how to do it right. This is how it works:

The senses system is a physics based system. Each sense is made up of basically one sensing object, one function, and two variables. All senses will eventually be part of a Senses Class.

SIGHT
Sight is just a collision test between a cone primitive that represents eyes. If there is a collision between the cone and an object, it makes a Boolean named seen equal to true. An arguent is used so that you can easily make something see whatever object you type in the parenthesis. The transparency of the cone represents the quality of sight. The wideness of the cone represents the field of view. The height scale of the cone represents nearsightedness or far farsightedness. The eyes variable is the cone primitive.

Here is some a pseudocode skeleton of sight.
function See(object)
{
seen = true;seeing = true;
if isCollisionBetween(eyes,object){}
if (seen){}
while (seeing){}
}
SMELL
Smell is a collision test also, represented by a sphere primitive, but instead of detecting collision with an object, it is a collision with a particle system. The amount of particles that go inside of the sphere represent the strength of the smell. The type name of the particle system determines the type of smell. The nose variable is the sphere primitive.
function Smell(object)
{
smelled = true;smelling = true;
if isCollisionBetween(nose,object){}
if (smelled){}
while (smelling){}
}
TOUCH
Touch is a collision test also. It requires no primitive shapes. The character or object itself detects the collision. It can be used for multiple game objects:
function Touch(object1,object2,object3)
{
touched = true;touching = true;
if isCollisionBetween(toucher,object1){}
if (touched){}
while (touching){}
}
HEARING
I decided to make hearing work a little differently. Hearing is just a volume and distance test. It checks if the distance between the hearing object and the sound object. It also checks if the volume is above or bellow a certain value.
function Hear(object){
heard = true;
hearing = true;
if (heard && volume >= 30 && distance <= 3)
{}while (hearing){}
}
TASTE
Taste works just like touch, except it has a primitive shape that does the collision witih another game object.
function Taste(object)
{
tasted = true;tasting = true;
if isCollisionBetween(tongue,object){}
if (tasted){}
while (tasting){}
}
This systems is easy to implement in any language or game engine that has particle systems, collisions, and sounds. I was even able to implement it in the Little Big Planet game using their tag system. When there was a collision, it would display a speech bubble that said either "Seen, Heard, Touched" etc.

Update:

Okay, so this was so easy to implement. Only took about 3 lines of code:

Posted Image

Posted Image
if isCollisionBetween(eyes,box) then
setText(text, "I see a ".. readout)
else setText(text,"I see nothing")
function See(object)
if isCollisionBetween(eyes,object) then
readout = getName(object)
setText(text, "I see a ".. readout)
else setText(text,"I see nothing")
end
end
The above code is how the final function looks. And the way you use it is simple:
See(box)




Going to get started on this again. Sight works well so far accept for obstructed objects. This is an easy fix though, because the cone can collide with multiple objects, although I don't think I have a way to display multiple readouts on screen yet, or even if I could, I wouldn't know how to display them all. This is good though, because I couldn't display the things I see in real life on a screen (things like the small particles you can see when the sunlight shines through the window. 

 

I can use either a dictionary or a table and store all objects that can be seen in it. I can actually do this for each sense so that I can keep things together. 

Making some progress rather quickly. Thanks to Vegas for his help on this one (not on this site). I use the Maratis Game Engine to implement it. You can follow the process closer here:

 

http://forum.maratis3d.com/viewtopic.php?id=763

After reading a wikipedia article on sensory cues, I have a better idea of how to make this senses system more realistic. 

 

http://en.wikipedia.org/wiki/Sensory_cue

I will now be adding some more functionality using fuzzy logic. This will allow me to get more realistic interactions. Combining these this senses system with a sort of AI thinking system (using fuzzy logic) I think I can can program an NPC to behave realistically autonomously. 

PARTNERS