Closest object check by Xander20th Mar 2004 18:38
|
---|
Summary Use this code to find the object in the game that is closest to another object Description This is a subroutine that can be used in a 3D game to find the object in the game that is closest to another object, namely the player object. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com checkdistance: maxdist#=0.0 closest=0 for obj=firstobj to lastobj if object exist(obj) diffx#=object position x(player)-object position x(obj) diffy#=object position y(player)-object position y(obj) diffz#=object position z(player)-object position z(obj) distance#=sqrt(diffx#^2+diffy#^2+diffz#^2) if distance#>closest=obj:maxdist#=distance# endif next obj return |