For simple box collision,
the logic is:
if the camera z position is greater than the object z position - 30 and the z position is less than the object z position + 30 and the x pos > object x pos - 30 and the x pos < object x pos + 30
collision = 1
endif
then you would have:
if collision = 1
xcam# = oldxcam#
zcam# = oldzcam#
endif
this is for stationary square objects. it will give the object a 60 by 60 world units field, the camera cannot go within 30 units of the object's center
when you hit the object, and face a little to the right, u will not goto the right a little like in any good 3d professional game. now you need sliding collision
with sliding collision, you find which of the four faces the player is colliding with teh object, then u find his rotation. these determine how much he slides.
I use classic, not dbpro, currently, so im not sure how the code will help
...
gosub collision_detection
gosub enact_collision
gosub sliding_collision
...
collision_detection:
rem Collision for the Hut
cox# = object position x(6)
coz# = object position z(6)
colhut = 0
if zc# > coz# - 150
if zc# < coz# + 150
if xc# > cox# - 150
if xc# < cox# + 150
colhut = 1
endif
endif
endif
endif
return
...
enact_collision:
rem enact collision
if colhut = 1
xc# = oldxc#
zc# = oldzc#
endif
return
...
sliding_collision:
rem Sliding col hut
rem Face 1
if xc# > object position x(6) - 150
if xc# < object position x(6) + 150
if zc# > object position z(6)
if keystate(17) = 1
if colhut = 1
slide# = camyrot# - 180
slide# = slide# / 12
if keystate(42) = 1 then slide# = slide# * 2
xc# = xc# - slide#
endif
endif
endif
endif
endif
rem Face 2
if zc# > object position z(6) - 150
if zc# < object position z(6) + 150
if xc# > object position x(6)
if keystate(17) = 1
if colhut = 1
slide# = camyrot# - 270
slide# = slide# / 12
if keystate(42) = 1 then slide# = slide# * 2
zc# = zc# + slide#
endif
endif
endif
endif
endif
rem Face 3
if zc# > object position z(6) - 150
if zc# < object position z(6) + 150
if xc# < object position x(6)
if keystate(17) = 1
if colhut = 1
slide# = camyrot# - 90
slide# = slide# / 12
if keystate(42) = 1 then slide# = slide# * 2
zc# = zc# - slide#
endif
endif
endif
endif
endif
rem Face 4
if xc# > object position x(6) - 150
if xc# < object position x(6) + 150
if zc# < object position z(6)
if keystate(17) = 1
if colhut = 1
slide# = camyrot#
if slide# > 269 then slide# = slide# - 360
slide# = slide# / 12
if keystate(42) = 1 then slide# = slide# * 2
xc# = xc# + slide#
endif
endif
endif
endif
endif
return
...
note im also kinda new to coding, so this might not be the most efficient way for me to do it.
and i dont have backwords or sidestep sliding collision yet, those will be worked on later
for circular collision (with which i dont think u can get sliding collision) you use the distance formula; collision would = 1 if the distance is less than a certain amount
for collision with a box that is rotated 45* (for which i havent gotten sliding collision for yet) :
rem collision box rotated 45*
col8 = 0
if abs((xc# - object position x(8))) + abs((zc# - object position z(8))) < 150 then col8 = 1
if i havent explained well enough and you need help just ask
and of course u will need to change the object numbers in the code to suit yourself
for y collision (upraised platforms and ramps) you find where the camera is in relation to the ramp or platform, and that corresponds to his height
i think this code gives a platform and three ramps around it and an ATTEMPT at the parts between the ramps
ycollision7:
posx# = xc# - object position x(7) - 200
posz# = zc# - object position z(7) - 200
hgty# = 0
coly# = 0
if xc# > object position x(7) + 200 and xc# < object position x(7) + 400 and zc# > object position z(7) - 200 and zc# < object position z(7) + 200
hgty# = ((xc# - object position x(7)) - 200) * -1 + 200
endif
if zc# < object position z(7) - 200 and zc# > object position z(7) - 400 and xc# < object position x(7) + 200 and xc# > object position x(7) - 200
hgty# = ((zc# - object position z(7)) - 200) + 600
endif
if xc# < object position x(7) - 200 and xc# > object position x(7) - 400 and zc# > object position z(7) - 200 and zc# < object position z(7) + 200
hgty# = ((xc# - object position x(7)) - 200) + 600
endif
if xc# < object position x(7) + 200 and xc# > object position x(7) - 200 and zc# > object position z(7) - 200 and zc# < object position z(7) + 200
hgty# = 200
endif
if xc# > object position x(7) + 200 and xc# < object position x(7) + 400 and zc# < object position z(7) - 200 and zc# > object position z(7) - 400
hgt1# = ((zc# - object position z(7)) - 200)
hgt2# = ((object position x(7) - xc#) - 200)
if abs(hgt2#) > abs(hgt1#) then hgty# = hgt1# * -2 + 400
if abs(hgt2#) > abs(hgt1#) then print "2 > 1"
if abs(hgt1#) > abs(hgt2#) then hgty# = hgt2# * -2 + 400
if abs(hgt1#) > abs(hgt2#) then print "1 > 2"
if abs(hgt1#) = abs(hgt2#) then hgty# = hgt1# * -2 + 400
if abs(hgt1#) = abs(hgt2#) then print "1 = 2"
print "aaaA"
endif