TGC Codebase Backup



Fast Box Collision Function by Preston C

30th Aug 2003 8:44
Summary

A simple collision function I created during development of my first alienware competition entry.



Description

A simple collision function.
You must specify what objects to check for collision for o1 and o2.
objectwidth and objectdepth should be the width and depth of the collision box for o2
should o2 be 0, the function will search for collision from 1 to maxobjects
if nocollide is specified, if an object collides with the object specified
in nocollide, it will return 0.



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