When you create an object collision box, you are surrounding the object with an invisible boundary in the shape of a box. When you make an object, it is positioned in 3D space at X,Y,Z location (0,0,0) . Generally, an object's center is also at (0,0,0) .
You want to be sure that the invisible boundary (the collision box) is around the entire object. To create it, always create it from the lowest values to the highest values. At creation or loading, objects face into the screen - that means they face in the +Z direction. The back of the object is pointing towards you. Therefore, to make a collision box from the lowest point to the highest, the lowest point is zero minus half of the size of the object and the highest point is zero plus half of the size of the object. That is what TheComets functions is doing:
rem get object's size
sx#=object size x(obj)/2.0
sy#=object size y(obj)/2.0
sz#=object size z(obj)/2.0
rem make the collision box
make object collision box obj,0-sx#,0-sy#,0-sz#,sx#,sy#,sz#,col
Quote: "I'm in the same class as Clay, infact I sit right next to him, and he just tried what Obese said, and it didn't work, and then he tried the function and that didn't work."
Usually, a collision box is set up once, when the object is created or loaded. Once the collision box is setup, as I mentioned in a post above, an object using
MAKE OBJECT COLLISION BOX can only detect collision with another object that has collision set up using
MAKE OBJECT COLLISION BOX
Here's a quick example using TheComet's function:
remstart
==============================================================
= Title : Collision box test
= Author : latch
= Date : 01/31/2011
= Update :
= Version: .01
==============================================================
Comments
Use a collision box on differently shaped objects
to test for collision.
==============================================================
remend
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
autocam off
set display mode 800,600,32
sync on
sync rate 60
rem =============================================================
rem = MAIN
rem =============================================================
_main:
rem setup objects
gosub _init
position camera 500,100,300
point camera 500,0,500
do
gosub _move_objects
sync
loop
end
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
_init:
rem create a matrix for reference
make matrix 1,1000,1000,25,25
rem make a few objects to test for collision
make object cone 1,25
MakeObjectCollisionBox(1,0)
make object sphere 2,18
MakeObjectCollisionBox(2,0)
make object box 3,5,5,80
MakeObjectCollisionBox(2,1)
rem position the objects
position object 1,300,13,500
position object 2,700,9,500
position object 3,500,5,500
rem set the initial x directions and speed the objects will move
x1=rnd(6)+1
x2=0-(rnd(6)+1)
return
`================================================================
_move_objects:
rem rotate object 3
turn object right 3,1
rem move object 1 and test for collision with object 3
position object 1,object position x(1)+x1,object position y(1),object position z(1)
if object collision(1,3)=1
rem reverse direction
x1=0-x1
position object 1,object position x(1)+x1,object position y(1),object position z(1)
endif
rem move object 2 and test for collision with object 3
position object 2,object position x(2)+x2,object position y(2),object position z(2)
if object collision(2,3)=1
rem reverse direction
x2=0-x2
position object 2,object position x(2)+x2,object position y(2),object position z(2)
endif
rem if either of the obejcts are outside of a certain area, then reverse direction
if object position x(1) < 300 or object position x(1) > 700 then x1=0-x1
if object position x(2) < 300 or object position x(2) > 700 then x2=0-x2
return
rem =============================================================
rem = FUNCTIONS
rem =============================================================
function MakeObjectCollisionBox(obj,col)
remstart
setup an object collision box
obj == the object number to set up collision on
col == the collision flag
0 = Non-rotating collision box
As the object rotates, the collision box
holds it's orginal orientation. Useful for
box sliding collision
1 = Rotating colision box
The collision box will rotate according to the
objects orientation. A little more accurate
than non-rotating collision but a little
slower as well
remend
rem get object's size
sx#=object size x(obj)/2.0
sy#=object size y(obj)/2.0
sz#=object size z(obj)/2.0
rem make the collision box
make object collision box obj,0-sx#,0-sy#,0-sz#,sx#,sy#,sz#,col
endfunction
Enjoy your day.