Here's my coding. try this download
set display mode 1024,768,32
hide mouse : color backdrop 0,rgb(0,0,0)
set text font "times new roman" : set text size 18
set text transparent
sync on : sync rate 100
sync : center text 515,382,"Loading Media..." : sync
gosub Load_Media
gosub Setup_Game
do
gosub control_player
gosub control_stats
sync
loop
`----------------------------------------------------------------------------------------
control_player:
oldx# = object position x(PlayerObj)
oldy# = object position y(PlayerObj)
oldz# = object position z(PlayerObj)
rem apply gravity, and user changes to movement
angy# = object angle y(PlayerObj)
vx# = 0
vz# = 0
rem player movements
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if rightkey()=1 then yrotate object PlayerObj,wrapvalue(object angle y(PlayerObj)+1)
if leftkey()=1 then yrotate object PlayerObj,wrapvalue(object angle y(PlayerObj)-1)
if downkey()=1 then move object PlayerObj,-1
if upkey()=1 then move object PlayerObj,1
rem this would be the player's final position without collision
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,4,0)
if collide>0
rem how flat is this ground
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
rem FLAT, stick
oldy# = sc_getStaticCollisionY()
else
rem STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
if ny#>slope#
rem only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
rem if player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
rem nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
endif
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,4,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
endif
rem position the player
position object PlayerObj,x#,oldy#,z#
sc_updateObject PlayerObj
return
`----------------------------------------------------------------------------------------
control_stats:
rem Track hero with camera
x#=object position x(PlayerObj)
y#=object position y(PlayerObj)
z#=object position z(PlayerObj)
a#=object angle y(PlayerObj)
d#=30.0
h#=15.0
s#=5.0
set camera to follow x#,y#,z#,a#,d#,h#,s#,1
set text to bold
fps$="DBPro Fps: "+str$(screen fps()) : text 5,5,fps$
set text to normal
return
`----------------------------------------------------------------------------------------
Setup_Game:
rem player movement vector
global vx# as double float
global vy# as double float
global vz# as double float
global gravity# as double float : gravity# = -0.1
global slope# as double float : slope# = 0.5
global ground as integer : ground = 1
global jumptimer as integer : jumptimer = 0
rem make player
PlayerObj=1 : make object sphere PlayerObj,10
position object PlayerObj,0,0,0
sc_setupObject PlayerObj,0,1
return
`----------------------------------------------------------------------------------------
Load_Media:
rem Load SkyObj and WorldObj
WorldObj=2 : load object "media/world/starter.x",WorldObj
sc_setupComplexObject WorldObj,1,2
sc_setupObject WorldObj,1,0
rem load images
return
if memblock exist(1) then delete memblock 1
If you do something 10,000 times. Your bound to get it right once.