Fast Box Collision Function by Preston C30th Aug 2003 8:44
|
---|
Summary A simple collision function I created during development of my first alienware competition entry. Description A simple collision function. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com function collide(o1,o2,objectwidth,objectdepth,objectheight,nocollide,maxobjects) yep=0 if o1<>o2 if o2>0 if object position x(o1)<object position x(o2)+objectwidth and object position x(o1)>object position x(o2)-objectwidth if object position z(o1)<object position z(o2)+objectdepth and object position z(o1)>object position z(o2)-objectdepth if object position y(o1)<object position y(o2)+objectheight and object position y(o1)>object position y(o2)-objectheight yep=1 endif endif endif endif if o2=0 for j=1 to maxobjects if object position x(o1)<object position x(j)+objectwidth and object position x(o1)>object position x(j)-objectwidth if object position z(o1)<object position z(j)+objectdepth and object position z(o1)>object position z(j)-objectdepth if object position y(o1)<object position y(j)+objectheight and object position y(o1)>object position y(j)-objectheight yep=1 if j=nocollide then yep=0 endif endif endif next j endif endif endfunction yep |