Well I think I figured out my problem but I dunno what to do about it. I have another box (#2) That collides with the detecting box (#3) but needs to be where it is. As far as I can see when I test to see if the number is greater than 4 (the numbers of the boxes I want to test for) the number is 2 (because box 2 is sitting there colliding) so it returns false. When I delete box 2 it works perfectly and this bug doesnt occur with the box sitting on the ground. My question is, is there a way to ignore the collision between two boxes?
This is hard to follow so here is the code:
Rem Project: phypickobject1
Rem Created: 10/08/2006 04:38:53
phy start
sync on
sync rate 0
autocam off
color backdrop 0
make light 1
set directional light 1, -5, -5, 5
position camera -20, 20, -25
point camera 0, 10, 0
make object box 1, 1000, 1, 1000
color object 1,RGB(0,128,128)
phy make rigid body static box 1
make object box 3, 100, 1.5, 100
color object 3,RGB(0,0,0)
boxnum=4
boxend=6
height=0
for test=0 to 4
switch=0
if switch=0
for boxnum=boxnum to boxend
make object box boxnum,6,1,2
position object boxnum,0,height,ypos
phy make rigid body dynamic box boxnum
phy set rigid body mass boxnum,10
phy set rigid body linear velocity boxnum,0,0.1,0
inc ypos,2
next boxnum
boxend=boxnum+3
switch=1
inc height,2
ypos=-2
inc boxnum
endif
if switch=1
for boxnum=boxnum to boxend
make object box boxnum,2,1,6
position object boxnum,ypos,height,2
phy make rigid body dynamic box boxnum
phy set rigid body mass boxnum,10
phy set rigid body linear velocity boxnum,0,0.1,0
inc ypos,2
next boxnum
boxend=boxnum+3
switch=0
inc height,2
ypos=0
inc boxnum
endif
next test
make object box 2,6,20,6
position object 2,0,0,2
color object 2,RGB(0,0,0)
hide object 2
Rem ***** Main Source File *****
do
gosub _drag_object
If mouseclick()>0
If OBJECT COLLISION(cursorobj, 2)=1 then text 0,0,"True"
endif
If OBJECT COLLISION(3, 0) =7 then text 0,0,"Hit"
Point Camera 0,0,0
If leftkey()=1
TURN CAMERA LEFT 90
MOVE CAMERA .5
TURN CAMERA RIGHT 90
endif
If rightkey()=1
TURN CAMERA right 90
MOVE CAMERA .5
TURN CAMERA left 90
endif
phy update
sync
loop
_drag_object:
if mouseclick()=0 then pickmode=0 : cursorobj=0
mclick=mouseclick()
if mclick>0
if pickmode=0
cursorobj=pick object(mousex(),mousey(),4,100)
text 15,0,"object = "+str$(cursorobj):sync
if cursorobj>0
pickmode=mclick
pickdistance#=get pick distance()
pickfromx#=get pick vector x()
pickfromy#=get pick vector y()
pickfromz#=get pick vector z()
if pickmode=1
objx#=object position x(cursorobj)
objy#=object position y(cursorobj)
objz#=object position z(cursorobj)
else
objx#=object angle x(cursorobj)
objy#=object angle y(cursorobj)
objz#=object angle z(cursorobj)
pickdiffx#=mousemovey() : pickdiffx#=0
pickdiffy#=mousemovex() : pickdiffy#=0
endif
else
highlightobj=0
endif
endif
if pickmode>0
if pickmode=1
pick screen mousex(),mousey(),pickdistance#
picktox#=get pick vector x()
picktoy#=get pick vector y()
picktoz#=get pick vector z()
pickdiffx#=picktox#-pickfromx#
pickdiffy#=picktoy#-pickfromy#
pickdiffz#=picktoz#-pickfromz#
grid=0
if grid=1
pickdiffx#=int(pickdiffx#/5)*5
pickdiffy#=int(pickdiffy#/5)*5
pickdiffz#=int(pickdiffz#/5)*5
endif
phy set rigid body position cursorobj,objx#+pickdiffx#,objy#+pickdiffy#,objz#+pickdiffz#
`phy set rigid body linear velocity cursorobj,objx#+pickdiffx#,objy#+pickdiffy#,objz#+pickdiffz#
`position object cursorobj,objx#+pickdiffx#,objy#+pickdiffy#,objz#+pickdiffz#
else
pickdiffx#=pickdiffx#+mousemovey()
pickdiffy#=pickdiffy#+mousemovex()
grid=0
if grid=1
tpickdiffx#=int(pickdiffx#/22.5)*22.5
tpickdiffy#=int(pickdiffy#/22.5)*22.5
else
tpickdiffx#=pickdiffx#
tpickdiffy#=pickdiffy#
endif
`rotate object cursorobj,wrapvalue(objx#-tpickdiffx#),wrapvalue(objy#-tpickdiffy#),objz#
rotate camera 0,wrapvalue(objx#-tpickdiffx#),wrapvalue(objy#-tpickdiffy#),objz#
endif
endif
endif
return