I am using sparky's collision code for a first person persective collsion. It works great but I need help with slowing down movement of the player. I tried messing with the "position object 2, x#, oldy#, z#" and the "if keystate(32)=1 then vx# = vx# + cos(angy#)" stuff, but it just screws up collsion and placment of the player. Any help on slowing down movement speed would be greatly appreciated.
do
positionCameraToObject(2,view)
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)
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#)
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#
oldy# = sc_getStaticCollisionY()
else
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#
ground = 1
vy# = 0
else
ground = 0
if ny#<-slope# then vy# = gravity#
endif
else
oldy# = oldy# + vy#
ground = 0
endif
if ground = 1 then if jumptimer>0 then dec jumptimer
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
endif
position object 2, x#, oldy#, z#
sc_updateObject 2
sync
loop
function positionCameraToObject(obj,thirdPerson)
position camera 0, object position x(2),object position y(2),object position z(2)
rotate camera 0, object angle x(2),object angle y(2),object angle z(2)
if thirdPerson=1
pitch camera down 0, 10
move camera 0, -30
endif
endfunction