hey all, i'm still learning about DBPro and currently i'm struggling with collision. I got this code from this forum to help me.
autocam off
set image colorkey 255,0,255
sync on
srate=60
sync rate srate
color backdrop 0
set camera range 1,5000
set ambient light 75
load object "level.x",1
set object transparency 1,2
dir$=get dir$()
charht#=50
spd#=3
radius#=10.0
position camera 0,charh#,0
yrotate camera 180
checks=8
if checks<4 then checks=4
if checks>360 then checks=360
angwidth=360/checks
dim ang#(checks-1,2)
dim sort#(checks-1,2)
do
set cursor 0,0
print "Sync Rate set at ",srate," Press Enter to change"
print "FPS:",screen fps()
if scancode()=0 then hold=0
if returnkey()=1 and hold=0
hold=1
if srate=60
srate=0
else
srate=60
endif
sync rate srate
endif
oldx#=camera position x()
oldz#=camera position z()
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
ca#=camera angle y()
mx#=mousemovex()/4.0
my#=mousemovey()/4.0
if mouseclick()=0 then show mouse
if mouseclick()>1
hide mouse
position mouse 320,240
xrotate camera wrapvalue(camera angle x()+my#)
yrotate camera wrapvalue(camera angle y()+mx#)
if camera angle x()>80 and camera angle x()<180 then xrotate camera 80
if camera angle x()<270 and camera angle x()>180 then xrotate camera 270
endif
control camera using arrowkeys 0,10,2
print "Camera angle:",camera angle y()
gosub _collision
gosub _ramp
if spacekey()=1 then position camera 0,200,0
sync
loop
_ramp:
cx#=camera position x()
cz#=camera position z()
oldht#=camera position y()
sub#=intersect object(1,cx#,oldht#,cz#,cx#,oldht#-(charht#*2),cz#)
ht#=(oldht#+charht#)-sub#
if sub#=0 then ht#=charht#
grav#=grav#-0.25
if oldht#+grav#<ht#
grav#=0.0
position camera cx#,ht#,cz#
else
ht#=oldht#+grav#
position camera cx#,ht#,cz#
endif
return
_collision:
for x=0 to checks-1
chx#=newxvalue(cx#,x*angwidth,100)
chz#=newzvalue(cz#,x*angwidth,100)
ang#(x,1)=intersect object(1,cx#,cy#,cz#,chx#,cy#,chz#)
if ang#(x,1)=0 then ang#(x,1)=999999
ang#(x,2)=x*angwidth
sort#(x,1)=ang#(x,1)
sort#(x,2)=ang#(x,2)
next x
for x=0 to checks-2
for y=x+1 to checks-1
if ang#(x,1)>ang#(y,1)
temp#=ang#(x,1)
temp2#=ang#(x,2)
ang#(x,1)=ang#(y,1)
ang#(x,2)=ang#(y,2)
ang#(y,1)=temp#
ang#(y,2)=temp2#
endif
next x
next y
print "Angle to closest wall:",ang#(0,2)
print "Distance to that wall:",ang#(0,1)
prev=wrapvalue(ang#(0,2)-90)/angwidth
nxt=wrapvalue(ang#(0,2)+90)/angwidth
newd#=radius#-ang#(0,1)
newa#=wrapvalue(ang#(0,2)-180)
newd1#=radius#-sort#(prev,1)
newa1#=wrapvalue(sort#(prev,2)-180)
newd2#=radius#-sort#(nxt,1)
newa2#=wrapvalue(sort#(nxt,2)-180)
if ang#(0,1)<radius# and ang#(0,1)>0.0
repx#=newxvalue(cx#,newa#,newd#)
repz#=newzvalue(cz#,newa#,newd#)
position camera repx#,cy#,repz#
endif
cx#=camera position x()
cz#=camera position z()
if sort#(prev,1)<radius# and sort#(prev,1)>0.0
repx1#=newxvalue(cx#,newa1#,newd1#)
repz1#=newzvalue(cz#,newa1#,newd1#)
position camera repx1#,cy#,repz1#
endif
cx#=camera position x()
cz#=camera position z()
if sort#(nxt,1)<radius# and sort#(nxt,1)>0.0
repx2#=newxvalue(cx#,newa2#,newd2#)
repz2#=newzvalue(cz#,newa2#,newd2#)
position camera repx2#,cy#,repz2#
endif
return
However, when i tried to use my own map, the camera position at the first time is too high for some reason. When i tried to change the "position camera", it's still having the same result. Any help? I also include my map and everything in the attachment..
i'm a newbie...