Game Development Community

dev|Pro Game Development Curriculum

Proximity Math Utilities

by Orion Elenzil · 07/03/2006 (11:11 am) · 3 comments

Download Code File

see attached .zip for funcion bodies.
the .zip also has a large image showing a crowd scene and the various mutual-proximity values for one person.

// Basically these allow you to get a value between two players
// which is based on the distance between the players and how much each one is facing the other.
// the value is the same from each player's point of view.
//
// this is really just two workhorse functions and a bunch of conveniences on top.
// the two workhorses are:
//
// rangeRadial  : distance = 0     yields: 1.
//              : distance = range yields: 0.
//              : distance > range yields: negative values.
//
// rangeAngular : angle    = 0     yields: 1.
//              : angle    = range yields: 0.
//              : angle    > range yields: negative values.
//
// the rest of the functions are just combinations of these.
// 
// "directed" is just rangeRadial * rangeAngular, with negative values pre-clamped to zero.
// "mutual"   is just the average of the given range function for each point of view.
// 
// So for example the mutual directed range of two players is highest when they're near and facing each other,
// and gets smaller as either one turns or moves away.
//
// The functions behave well in degenerate situations. (ie, they don't divide by zero)

#1
07/03/2006 (12:21 pm)
Very handy, Thanks for contributing Orion!
#2
07/03/2006 (2:46 pm)
Wow, this is great, just what I need :) Thanks Orion ..
#3
07/03/2006 (4:02 pm)
thanks guys! glad it's useful to someone.
here's some screenshots showing various proximity values.
the exact values can all be easily tuned by changing the range limits.

elenzil.com/images/proxcases.jpg
much larger version of the same pic