Check this out:
global CameraDistance# as float
global AngleX# as float
global AngleY# as float
CameraDistance#=500
Rem Project: oldcode
Rem Created: Wednesday, July 28, 2010
Rem ***** Main Source File *****
Rem Project: loop
Rem Created: Tuesday, May 18, 2010
global coll
global gravity#=10.0
global test# as float
global Speed# as float
global FallCondition=0
global FallDirectionX# as float
global FallDirectionY# as float
global FallDirectionZ# as float
global FallPitch# as float
Rem ***** Main Source File *****
sync on
sync rate 60
autocam off
position camera -200,200,-200
`load loopy world
load object "loop.dbo",1
yrotate object 1,90
global LoopY# as float
LoopY#=object angle y(1)
sc_setupcomplexobject 1,1,2
`make a 'person'
global height as float
height=100
make object box 2,height/3,height,height/6
position object 2,0,height/2+100,0
set shadow shading on 2
set shadow position -1,-100,500,-100
REM NEW!!!
global camang as float
sc_setupobject 1,1,0
sc_setupobject 2,1,0
`automatic object collision 1,1,0
`set object collision on 1
`automatic object collision 2,1,1
`set object collision on 2
make object sphere 3,10
color object 3,rgb(255,0,0)
DO
`collision()
sc_updateobject 1
sc_updateobject 2
if inkey$()<>"t" then player()
`set camera to follow object position x(2),object position y(2),object position z(2),camang,200,4,20,0 REM EDITED!!!
position object 3,object position x(2),object position y(2),object position z(2)
rotate object 3,object angle x(2),object angle y(2),object angle z(2)
turn object right 3,camang
move object up 3,50
move object 3,20
RotateCamera()
text 10,10,"x:"+str$(object angle x(2))
text 10,30,"y:"+str$(object angle y(2))
text 10,50,"z:"+str$(object angle z(2))
text 10,70,"xpos:"+str$(object position x(2))
text 10,90,"ypos:"+str$(object position y(2))
text 10,110,"zpos:"+str$(object position z(2))
text 10,130,"coll:"+str$(coll)
text 10,150,"test:"+str$(test#)
sync
LOOP `pardon the pun :)
function collision()
if sc_objectcollision(1,2) then end
endfunction
function player()
if object position y(2)>50 then move object down 2,gravity#
REM Move player
if keystate(17) and object position y(2)<60
inc Speed#
if Speed>68.6 then Speed#=68.6
` Speed#=41.4 `min speed to go around=41.4 max speed before it doesn't work=68.6
endif
if keystate(31)
dec Speed#
if Speed#<-10 then Speed#=-10
endif
if spacekey()=1 then Speed#=0
move object 2,Speed#
turn object right 2,90
move object 2,Speed#/7.5
turn object left 2,90
REM Do ground check
`get start and end points for ray cast
oldx#=object position x(2)
oldy#=object position y(2)
oldz#=object position z(2)
pitch object down 2,90
move object 2,height*abs(Speed#)+height
newx#=object position x(2)
newy#=object position y(2)
newz#=object position z(2)
move object 2,-(height*abs(Speed#)+height)
pitch object up 2,90
`do the ray cast
coll=sc_raycastgroup(1,oldx#,oldy#,oldz#,newx#,newy#,newz#,2)
if coll<>0
`get collision data
nx#=sc_getcollisionnormalx()
ny#=sc_getcollisionnormaly()
nz#=sc_getcollisionnormalz()
if ny#>0.0 then FallCondition=0
if ny#<>0.0
`make an adjustment to z normal (cheating a bit here to make it work)
d#=sc_getcollisiondistance()
`adjust player angle to suit
point object 2,object position x(2)+nx#,object position y(2)+ny#,object position z(2)+nz#
`move 'up' to half height above ground
move object 2,(height/2)-d#
if FallCondition>0 then position object 2,object position x(2),object position y(2)+FallDirectionY#,object position z(2)
`re-adjust direction
pitch object down 2,90
endif
if (LoopY#=90 or LoopY#=270) `and ny#<1.0 and nz#<0
if ny#<1.0 and nz#<0 then turn object right 2,180
endif
if LoopY#=0 or LoopY#=180
if ny#<1.0 and nx#>0 then turn object left 2,90
if ny#<1.0 and nx#<0 then turn object right 2,90
endif
rem find the player's direction angle
turn object right 2,camang
fx#=object position x(2)
fy#=object position y(2)
fz#=object position z(2)
move object 2,1
fx#=object position x(2)-fx#
fy#=object position y(2)-fy#
fz#=object position z(2)-fz#
move object 2,-1
turn object left 2,camang `put it back
if fy#>0.0 then dec Speed#,(1.0-ny#)/2.0
if fy#<0.0 then inc Speed#,(1.0-ny#)/2.0
if ny#<0.0 and Speed#<15.0
position object 2,object position x(2),object position y(2)-60,object position z(2)
FallDirectionX#=-fx#*Speed#*20.0
FallDirectionY#=-fy#*Speed#*10.0
FallDirectionZ#=-fz#*Speed#*20.0
FallPitch#=object angle x(2)
Speed#=0
FallCondition=1
endif
text 0,200,str$(nx#)+" "+str$(ny#)+" "+str$(nz#)
text 0,220,str$(FallPitch#)
else
rotate object 2,0,0,0
if FallCondition>0
inc test#
turn object right 2,180
position object 2,object position x(2)+FallDirectionX#,object position y(2)+FallDirectionY#,object position z(2)+FallDirectionZ#
FallDirectionX#=FallDirectionX#*0.95 `for air friction
FallDirectionZ#=FallDirectionZ#*0.95
dec FallDirectionY#,gravity#/7
endif
endif
if keystate(30)
dec camang
endif
if keystate(32)
inc camang
endif
turn object right 2,camang
REM Do wall check
`get start and end points for ray cast
oldx#=object position x(2)
oldy#=object position y(2)
oldz#=object position z(2)
if FallCondition>0
position object 2,oldx#+FallDirectionX#*50,oldy#+FallDirectionY#*50,oldz#+FallDirectionZ#*50
else
move object 2,Speed#+height `I would use a Speed variable here
endif
newx#=object position x(2)
newy#=object position y(2)
newz#=object position z(2)
if FallCondition>0
position object 2,oldx#,oldy#,oldz#
else
move object 2,-(Speed#+height) `I would use a Speed variable here
endif
`do the ray cast
coll=sc_raycastgroup(1,oldx#,oldy#-20,oldz#,newx#,newy#-20,newz#,2)
if coll<>0
` dec FallCondition
` if FallCondition<0 then FallCondition=0
d#=sc_getcollisiondistance()
if d#<Speed#+height `I would use a Speed variable here
`get collision data
ny#=sc_getcollisionnormaly()
if abs(abs(ny#)-abs(cos(object angle x(2))))>0.707
position object 2,SC_getCollisionSlideX(),SC_getCollisionSlideY(),SC_getCollisionSlideZ()
Move object 2,-height
else
rotate object 2,0,0,0
endif
endif
endif
if object position y(2)<50.0 then position object 2,object position x(2),50,object position z(2)
endfunction
function regplay()
move object 2,(keystate(17)-keystate(31))*4
endfunction
function RotateCamera()
MX# as float
MX#=MOUSEMOVEX()
MY# as float
MY#=MOUSEMOVEY()
AngleY#=wrapvalue(AngleY#+(MX#/5.0))
AngleX#=(AngleX#+(MY#/5.0))
if AngleX#>70.0 then AngleX#=70.0
if AngleX#<-70.0 then AngleX#=-70.0
MouseScroll=-mousemovez()
CameraDistance#=CameraDistance#+MouseScroll
if CameraDistance#>8000.0 then CameraDistance#=8000.0
if CameraDistance#<10.0 then CameraDistance#=10.0
position camera 0,300,0 `the lookat point
rotate camera AngleX#,AngleY#,0.0
move camera -CameraDistance#
endfunction
It's a little messy, but it gets the job done. Try it out at 0deg, 90deg, 180deg, and 270deg.
The fastest code is the code never written.