Hi,
I'm a relative noob to DB - just been using DB Pro for a week - and having a problem with static collision boxes. I've included simple stripped down code below (I hope - if the posting works..)
Sorry if this is the wrong place for this question - if so please tell me where I should stick it (so to speak..)
The code creates a sphere and a series of boxes on a matrix. You can move the sphere, and sliding collision detection seems to be working when it hits the boxes. It's fine as long as you move, but if you move next to the boxes and take your finger off the key - it 'jumps' the sphere back a little way.
I figure I've missed something in the code - can anyone offer any advice or point me in the right direction please coz I can't see it!?
Cheers!
Code (NB - created in DBPro - unpatched)
`**********************************
`* Simple routine to test static
`* collision detection routine
`**********************************
sync on : sync rate 60 : hide mouse
`Create a matrix
make matrix 1, 1000, 1000, 20, 20
`Create a sphere - player controlled
make object sphere 10,50
position object 10,100,25,100
`Create a line of boxes
for x = 1 to 6
make object box 10+x,50,50,50
`make object collision box 10,
next x
`Make static collision boxes
for i = 1 to 6
position object 10+i,(i*50) + 200,25,300
make static collision box ((i*50)+200)-25,0,300-25,((i*50)+200)+25,50,300+25
next i
`Main program loop
do
`Get beginning settings
angleY# = object angle y(10)
X# = object position x(10)
Z# = object position z(10)
Y# = get ground height(1, x#,z#)
`Check for key presses
if escapekey() = 1 then exit
if leftkey()=1 then yrotate object 10, Wrapvalue(AngleY#-3)
if rightkey()=1 then yrotate object 10, Wrapvalue(angleY#+3)
if upkey()
XTest# = Newxvalue(X#, AngleY#, 5)
ZTest# = Newzvalue(Z#, AngleY#, 5)
move object 10, 5
endif
if downkey()
XTest# = Newxvalue(X#, AngleY#, -5)
ZTest# = Newzvalue(Z#, AngleY#, -5)
move object 10, -5
endif
`Position Camera
cameraZ# = Newzvalue(Z#,angleY#-180, 75)
cameraX# = Newxvalue(X#, AngleY#-180,75)
cameraY# = get ground height(1, cameraX#, CameraZ#)
position camera cameraX#, cameraY#+80, CameraZ#
point camera x#,y#+40,z#
`Collision Detection Bit
xPos#=object position x(10)
yPos#=object position y(10)
zPos#=object position z(10)
`each object - spheres and squares - have diameter of 50
if get static collision hit(x#-25, y#-25, z#-25, x#+25, y#+25, z#+25,xTest#-25, 0, zTest#-25, xTest#+25, 0, zTest#+25) = 1
xpos# = xpos# - get static collision x()
zpos# = zpos# - get static collision z()
text 10, screen height()/2, "xpos=" + str$(xpos#) + " zpos=" + str$(zpos#)
position object 10, xpos#, ypos#, zpos#
endif
sync
loop
"The question isn't who is going to let me; it's who is going to stop me." - Ayn Rand