Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Programming the 5 Senses (entry)

Sign in to follow this  
Tutorial Doctor


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


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 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 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 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){}}
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 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.


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


Screenshot%20%28941%29.pngif isCollisionBetween(eyes,box) thensetText(text, "I see a ".. readout)else setText(text,"I see nothing")function See(object)if isCollisionBetween(eyes,object) thenreadout = getName(object)setText(text, "I see a ".. readout)else setText(text,"I see nothing")endend
The above code is how the final function looks. And the way you use it is simple:
Sign in to follow this  


Recommended Comments

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. 

Share this comment

Link to comment

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. 

Share this comment

Link to comment

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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!