Hi mnemonic. Here's a different way to accomplish to run around a map.
For a character running around I can strongly suggest using Sparkys Collision DLL.
Found in this thread:
http://forum.thegamecreators.com/?m=forum_view&t=74762&b=5
Direct download link :
http://forumfiles.thegamecreators.com/?i=818917
Tutorial :
http://forum.thegamecreators.com/?m=forum_view&t=114275&b=7
If you can't bother reading that tutorial go to snippet 6, copy and paste this in DB. Make sure you run it first to check for errors.
sync on
sync rate 60
hide mouse
autocam off
radius# = 7.0
gravity# = -0.1
slope# = 0.5
ground = 1
jumptimer = 0
gosub makeLevel
gosub makePlayer
do
gosub MovePlayer
rem change view
if inkey$()="v" and vtimer<timer() then vtimer = timer()+300 : view = 1-view
positionCameraToObject(2,view)
text 0,20,"x rot: "+str$(object angle x(2))
text 0,40,"y rot: "+str$(object angle y(2))
text 0,60,"z rot: "+str$(object angle z(2))
text 0,80,"FPS: "+str$(screen fps())
text 0,100,"Touching Ground: "+str$(ground)
text 0,120,"x = "+str$(object position x(2))
text 0,140,"y = "+str$(object position y(2))
text 0,160,"z = "+str$(object position z(2))
if inkey$() = "q" then end
if shiftkey() = 1 then position object 2,0,50,0
sync
loop
makeLevel:
load object "orbitalrelay.x",1
sc_setupComplexObject 1,1,2
return
makePlayer:
make object sphere 2,radius#*2
position object 2,0,50,0
sc_setupObject 2,0,1
return
movePlayer:
rem rotate player with mouse
yrotate object 2,object angle y(2)+mousemovex()/3.0
xrotate object 2,object angle x(2)+mousemovey()/3.0
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
rem apply gravity, and user changes to movement
angy# = object angle y(2)
vx# = 0
vz# = 0
if vy#=0 and jumptimer=0 then vy# = vy# + 10*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 keystate(31)=1 then vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
if keystate(17)=1 then vx# = vx# + sin(angy#) : vz# = vz# + cos(angy#)
rem only jump if on ground, and a certain time after last jump
if ground=1
if spacekey()=1 and jumptimer=0 then vy# = vy# + 3.0 : jumptimer = 20
endif
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
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
if ground = 1 and jumptimer>0 then dec jumptimer
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
endif
rem position the player
position object 2,x#,oldy#,z#
sc_updateObject 2
return
function positionCameraToObject(obj,thirdPerson)
position camera object position x(2),object position y(2),object position z(2)
rotate camera object angle x(2),object angle y(2),object angle z(2)
if thirdPerson=1
pitch camera down 10
move camera -30
endif
endfunction
if memblock exist(1) then delete memblock 1
Replace load object "orbitalrelay.x",1 on line 41 with the file you're using.
Directly under it you see SC_setupcomplexobject 1,1,2
1 is the object number , 1 is the group , 2 is something .
Now you should be able to run your map. Add in your own code if you have any. Good luck !
I have build myself already a level with some weapon pickups and a gun that can shoot, running on different heights of terrain, running on slopes.
Hint : Stairs can be accomplished by laying a plane on the stairs , make it transparent and collidable using the SC_setup command and it will function as a slope, but look like stairs