GLOBAL RADIUS# AS DOUBLE FLOAT : RADIUS# = 49.5
Global PRotY# = 2.0
GLOBAL PRotZ# = 2.0
Global z# = .05
`------------------------------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.3
GLOBAL slope# AS DOUBLE FLOAT : slope# = .5
GLOBAL ground AS INTEGER : ground = 1
GLOBAL jumptimer AS INTEGER : jumptimer = 0
do
oldx# = OBJECT POSITION X(PYR)
oldy# = OBJECT POSITION Y(PYR)
oldz# = OBJECT POSITION Z(PYR)
camx# = CAMERA POSITION X(0)
camy# = CAMERA POSITION Y(0)
camz# = CAMERA POSITION Z(0) rem apply gravity, and user changes to movement
angy# = OBJECT ANGLE Y(PYR)
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
yrotate object PYR,object angle Y(PYR)+mousemovex()/3.0
xrotate object PYR,object angle X(PYR)+mousemovey()/3.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#)*10 : vz# = -VZ# - SIN(angy#)*10
IF KEYSTATE(30)=1 THEN vx# =-VX# - COS(angy#)*10 : vz# = VZ# + SIN(angy#)*10
IF KEYSTATE(31)=1 THEN vx# =-VX# - SIN(angy#)*10 : vz# = -VZ# - COS(angy#)*10
IF MOUSECLICK()=2 THEN vx# = VX# + SIN(angy#)*10 : vz# = VZ# + COS(angy#)*10
IF MOUSECLICK()=3 THEN vx# = VX# + SIN(angy#)*10 : vz# = VZ# + COS(angy#)*10
IF KEYSTATE(31)=1 AND MOUSECLICK()=2 THEN vx# =-VX# - SIN(angy#)*10 : vz# = -VZ# - COS(angy#)*10
IF KEYSTATE(31)=1 AND KEYSTATE(32)=1
vx# =-VX# - SIN(angy#)*10 : vz# = -VZ# - COS(angy#)*10
vx# = -VX# + COS(angy#)*10 : vz# = VZ# - SIN(angy#)*10
ENDIF
IF keystate(31)=1 and keystate(30)=1
vx# =-VX# - SIN(angy#)*10 : vz# = -VZ# - COS(angy#)*10
vx# = VX# - COS(angy#)*10 : vz# = -VZ# + SIN(angy#)*10
ENDIF
rem only jump if on ground, and a certain time after last jump
IF GROUND = 0 AND KEYSTATE(43)=1
ANIMATE = ANIMATE + 1
IF animate = 1 THEN POSITION CAMERA 0,camx#,CAMY#-0.5,camz# `move object down pyr,.5
IF animate = 4 THEN POSITION CAMERA 0,camx#,CAMY#-1.0,camz# `move object down pyr,.5
IF animate = 7 THEN POSITION CAMERA 0,camx#,CAMY#-1.5,camz# `move object down pyr,.5
IF animate = 10 THEN POSITION CAMERA 0,camx#,CAMY#-2.0,camz# `move object down pyr,.5
IF animate = 15 THEN POSITION CAMERA 0,camx#,CAMY#-1.5,camz# `move object down pyr,.5
IF animate = 18 THEN POSITION CAMERA 0,camx#,CAMY#-1.0,camz# `move object down pyr,.5
IF animate = 21 THEN POSITION CAMERA 0,camx#,CAMY#-0.5,camz# `move object down pyr,.5
IF animate = 22 THEN animate = 0
ENDIF
IF ground=1
IF spacekey()=1 AND jumptimer=0 THEN vy# = vy# + 7.2 : jumptimer = 10
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(0,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(0,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 PYR,x#,OLDY#,z#
sc_updateObject PYR
POSITION CAMERA 0, OBJECT POSITION X(PYR),OBJECT POSITION Y(PYR)+1,OBJECT POSITION Z(PYR)
ROTATE CAMERA 0,OBJECT ANGLE X(PYR),OBJECT ANGLE Y(PYR),OBJECT ANGLE Z(PYR)sync
loop
If you ask for all my code there is over 1500 line and much media.
if it can be fix with this much, since this is every thing to the collision it would be great.