here, i even updated the code a bit, build you leval at the fith leavel in the editor for this to position correcly.
` this program shows how to load an FPS Creator level
` and walk around it using Sparkys collition
` set up general properties
sync on
sync rate 30
autocam off
randomize timer()
global numSpheres as integer : numSpheres = 1
global radius# as double float : radius# = 10.0
global littleRadius# as double float : littleRadius# = 3.0
global rtimer as integer
global stimer as integer
global vtimer as integer
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
global syncmode as integer : syncmode = 60
global view as integer : view = 1
global hide as integer : hide = 0
global factor# as float
global factor# as float
dim factors(30) as float
set camera range 0.5, 30000
hide mouse
` move into the media directory
set dir "media"
` load the level and make a static mesh for it
load object "levelbank\testlevel\universe.dbo", 1,2
POSITION OBJECT 1, 0, 0, 0
sc_setupComplexObject 1,1,2 //sparkys set up here
` come out of the media directory
set dir ".."
make object box 2,10,10,10
position object 2,1000,510,-500
sc_setupObject 2,2,1
hide object 2
position camera 1000,510,-500
` our main loop
do
` react to key presses and move the controller
yrotate object 2,wrapvalue(object angle y(2)+(mousemovex()*0.1))
movePlayer(2)
positioncameratoplyr(2)
camera(0)
sync
loop
function positioncameratoplyr(num)
x#=object position x(num)
y#=object position y(num)
z#=object position z(num)
a#=object angle y(num)
d#=-5.0
h#=55.0
s#=1.0
set camera to follow 0, x#,y#,z#,a#,d#,h#,s#,1
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
oldx# = object position x(num)
oldy# = object position y(num)
oldz# = object position z(num)
endfunction positioncameratoplyr
function movePlayer(num)
rem rotate player with mouse
oldx# = object position x(num)
oldy# = object position y(num)
oldz# = object position z(num)
rem apply gravity, and user changes to movement
angy# = object angle y(num)
vx# = 0
vz# = 0
rem if player is jumping or falling then apply 'normal' gravity
rem if not attempt to keep the player stuck to the floor
if rightkey()=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
if leftkey()=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
if vy#=0 and jumptimer=0 then vy# = vy# + 5*gravity# else vy# = vy# + gravity#
if keystate(32)=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
if keystate(30)=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
if downkey()=1 then vx# = vx# + 2 * sin(angy#) : vz# = vz# + 2 * cos(angy#)
if upkey()=1 then vx# = vx# + (-2) * sin(angy#) : vz# = vz# + (-2) * cos(angy#)
rem only jump if on ground, and a certain time after last jump
if ground=1
if keystate(57)=1 and jumptimer=0 then vy# = vy# + 3.3 : jumptimer = 20
if keystate(82)=1 and jumptimer=0 then vy# = vy# + 3.3 : jumptimer = 20
endif
rem this would be the player's final position without collision
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
rem first handle gravity - seperated from horizontal movement
rem to achieve a more realistic effect
rem Method: simple - cast a sphere vertically down, if it hits the level then
rem position the object there (sticky collision) then move
rem on to horizontal movement
rem more complex - if we were to only use the simple method the player would be
rem allowed to climb almost vertical slopes. Alternative is to
rem get the normalY direction to work out how flat the gorund
rem below the player is, 0-slope# is flatter, slope#-1 is steeper.
rem if it's flat, use sticky collision, if it's steep slide the
rem player down the slope. Changing slope# determines how steep the
rem player can climb. NOTE: this also effects stairs.
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,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
rem ny#<0 means the player has hit a ceiling rather than a floor
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
rem jumptimer will decrease only when player is back on ground
rem creates a pause between two successive jumps
if ground = 1 and jumptimer>0 then dec jumptimer
rem handle horizontal movement as sliding
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,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
rem possible code for giving the player a jumping help up stairs...
rem might be useful if slope# is set very high but stairs are still required
`dy# = oldy#-sc_getStaticCollisionY()
`if dy#<slope# and dy#>0 and ground=1 then vy# = 0.5
endif
rem position the player
position object num,x#,oldy#,z#
sc_updateObject num
endfunction movePlayer
function camera(num)
oldx# = camera position x(num)
oldy# = camera position y(num)
oldz# = camera position z(num)
move camera num,-0.5
x# = camera position x(num)
y# = camera position y(num)
z# = camera position z(num)
collide = sc_sphereSlide(1,oldx#,oldy#,oldz#,x#,y#,z#,littleRadius#,num)
if collide>0
position camera num,sc_getCollisionSlideX(),sc_getCollisionSlideY(),sc_getCollisionSlideZ()
endif
endfunction camera
my signature keeps being erased by a mod So this is my new signature.