Ive asked about angled sliding collision before but now I have a code which does it, except that when you turn against a plain it makes yor character go all jittery, can anyone see why this is.
if object collision(1,0)>1
obj#=object collision(1,0)
ca#=object angle y(obj#)
while object collision(1,obj#)=1
x#=newxvalue(x#,ca#,1)
z#=newzvalue(z#,ca#,1)
position object 1,x#,y#,z#
endwhile
x#=newxvalue(x#,wrapvalue(ca#+180),1)
z#=newzvalue(z#,wrapvalue(ca#+180),1)
endif
Here is my whole program, if you need to look at it (forgive the quality)...
`***********************************
`****** Platform Game Program ******
`****** By Hamish McHaggis ******
`***********************************
Rem Setup Environment
sync on:hide mouse
gosub variables
gosub setup
gosub scenery
Rem Main Loop
do
gosub controls
gosub character
gosub camera
sync
loop
Rem Control Character
controls:
ox#=x#:oy#=y#:oz#=z#
if upkey()=1 then x#=newxvalue(x#,a#,walkspd#):z#=newzvalue(z#,a#,walkspd#)
if downkey()=1 then x#=newxvalue(x#,a#,0-walkspd#):z#=newzvalue(z#,a#,0-walkspd#)
if leftkey()=1 then a#=wrapvalue(a#-turnspd#)
if rightkey()=1 then a#=wrapvalue(a#+turnspd#)
if spacekey()=1 and jump#=0 then pgrav#=jumppower#:jump#=1
return
Rem Control Character
character:
inc y#,pgrav#
dec pgrav#,grav#
if get static collision hit(ox#-s#,oy#-s#,oz#-s#,ox#+s#,oy#+s#,oz#+s#,x#-s#,y#-s#,z#-s#,x#+s#,y#+s#,z#+s#)
dec x#,get static collision x()
dec y#,get static collision y()
dec z#,get static collision z()
pgrav#=0
jump#=0
endif
if object collision(1,0)>1
obj#=object collision(1,0)
if objtype#(obj#)=0 then gosub collision
if objtype#(obj#)=1 then gosub stairs
endif
if y#0
y#=y#+1
position object 1,x#,y#,z#
endwhile
y#=y#-1
if y#>oy#+50 then x#=ox#:y#=oy#:z#=oz#
pgrav#=0
jump#=0
return
Rem Control Camera
camera:
cx#=newxvalue(x#,a#,camposx#)
cy#=y#+camposy#
cz#=newzvalue(z#,a#,camposz#)
position camera cx#,cy#,cz#
point camera x#,y#,z#
return
Rem Setup Variables and Arrays For Program Attributes
variables:
x#=0:y#=20:z#=0:a#=0:s#=20
camposx#=-200:camposy#=100:camposz#=-200
walkspd#=15:turnspd#=3
jumppower#=30
grav#=1:pgrav#=0
dim objtype#(1000)
return
Rem Make Character
setup:
make object cylinder 1,s#*2
yrotate object 1,90
fix object pivot 1
make object collision box 1,-20,-20,-20,20,20,20,0
return
Rem Setup Scenery
scenery:
bc=makeblock(1000,20,1000,0,0,0)
colorblock(200,0,0,bc)
makestaticblock(1000,20,1000,0,0,0,bc)
objtype#(51)=makestairs(51,0.0,10.0,440.0,400.0,100.0,600.0,10)
make object plain 3,300,300
yrotate object 3,300
position object 3,100,0,0
return
`******************************************
`****** Functions For Making Objects ******
`******************************************
Rem Make box objects
function makeblock(sx,sy,sz,px,py,pz)
inc blockcount
make object box blockcount+100,sx,sy,sz
position object blockcount+100,px,py,pz
endfunction blockcount
Rem Texture box objects
function textureblock(t,tx,ty,blockcount)
texture object blockcount+100,t
scale object texture blockcount+100,tx,ty
endfunction
Rem Colour box objects
function colorblock(red,grn,blu,blockcount)
color object blockcount+100,rgb(red,grn,blu)
endfunction
Rem Make static objects
function makestaticblock(sx,sy,sz,px,py,pz,blockcount)
make static object blockcount+100
make static collision box px-sx/2,py-sy/2,pz-sz/2,px+sx/2,py+sy/2,pz+sz/2
delete object blockcount+100
endfunction
Rem Make stairs to walk up
function makestairs(objnum,px#,py#,pz#,sx#,sy#,sz#,numstairs)
sl#=sqrt(sy#^2+sz#^2)
rota#=sy#/sz#
rot#=atan(rota#)
make object plain objnum,sx#,sl#
xrotate object objnum,wrapvalue(90-rot#)
position object objnum,px#,py#+sy#/2,pz#+sz#/2.0
hide object objnum
objtype#=1
stepw#=sx#
stepl#=sz#/(numstairs+1)
steph#=sy#/(numstairs+1)
for stair=1000 to 999+numstairs
make object box stair,stepw#,steph#,stepl#
position object stair,px#,sh#+steph#*1.5+steph#*(stair-1000),(pz#+stepl#/2)+stepl#*(stair-999)
make static object stair
delete object stair
next stair
endfunction objtype#
Yum! Yum! Yum! Yum!