Chafari
Your code is great but it acts weird with 45 dgrees rotated walls
no rotation:
Rem * Title : Chafari Collision Concept
Rem Scorpyo - 2008
top:
rem ********** MAIN 1 ****************
set display mode 1024,768,32
hide mouse
sync on
sync rate 60
backdrop on
global x#,z#,h#,s#,a#
x#=10000.0:h#=0.0:z#=10000.0:turn=0
gosub Makematrix
gosub setambience
gosub Character
gosub makecube
set global collision off
gosub Resetcam
sync rate 60
rem *****MAIN LOOP******
do
if inkey$()="r" then x#=10000.0:z#=10000.0:s#=0.0
if inkey$()="e" then sync rate 0
if inkey$()="E" then sync rate 40
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
gosub Playercontrol
gosub printdata
rem call to camera changes subroutine ( bottom key row )
gosub camera_controls
rem terrain height check
gosub heightcheck
gosub checkcoll
position object 9999,x#,h#,z#
yrotate object 9999,a#
rem calls camera update subroutine
gosub update_camera
rem Update screen
sync
rem End loop
loop
rem ****** CREATE LEVEL ******
Makematrix:
rem create ground texture
cls rgb(0,100,20)
get image 2,0,0,250,250
rem Make landscape
landsize=23000:grid=30:mtxrandomize=1
make matrix 1,landsize,landsize,grid,grid
set matrix 1,1,0,0,1,1,1,1
prepare matrix texture 1,2,1,1
randomize matrix 1,mtxrandomize
rem ***********
rem get ground done
update matrix 1
return
setambience:
rem Create fog and ambience
set ambient light 80
if fog available()=1
fog on
fog distance 100000
fog color rgb(150,150,255)
endif
return
rem make object
makecube:
make object cube 1000,800
set object 1000,1,1,0,1,1,1,1
rem yrotate object 1000,45
position object 1000,10000,-200,10700
color object 1000,rgb(120,10,10)
return
printdata:
set cursor 0,0
rem set text opaque
rem debug check
print "Fps=",screen fps()
print "polygons=",statistic(1)
print "------player data-------"
print "x#= ",x#
print "z#= ",z#
print "player ground height h#= ",h#
print "camera ground height h2#= ",h#
print "angle#= ",a#
print "speed#= ",s#
print "---------------------------"
print "---------------------------"
print "press r to reset position"
print "W & S = walk"
print "mousemove x = turn"
print "mouse wheel = change camera distance from player"
print "R mouse + mouse move y = change camera height"
print "z and x rotate camera around the player"
return
Playercontrol:
rem ****Character walk ****
rem control walking with w and s keys
if inkey$()="w" and s#<5 then s#=s#+0.2
if inkey$()="s" and s#>-5 then s#=s#-0.2
rem control turning with mousemove along x axis
turn=mousemovex()
if turn<0 then a#=wrapvalue(a#-3)
if turn>0 then a#=wrapvalue(a#+3)
rem stop if "à" is pressed
if inkey$()="à" then s#=0.0
rem slow if "l"
if inkey$()="l" then s#=0.2
return
rem ****BUILD PLAYER****
rem object 9999
Character:
rem make cone
make object cone 9999,30
rem stretch cone
scale object 9999,100,300,100
rem tilt cone
xrotate object 9999,90
rem fix tilting angle
fix object pivot 9999
rem set object solid (no culling)
set object 9999,1,1,0
return
rem ********CAMERA ROUTINES***********
camera_controls:
rem reset intial camera pressing <
if inkey$()="<" then gosub Resetcam
rem camera views from high (m and M)
if inkey$()="m" then camdist=-1000:camhgt=500:set camera range 100,40000
if inkey$()="M" then camdist=-3000:camhgt=1000:set camera range 100,40000
rem look around (Right Mouse click + mouse move)
if inkey$()="z" then camrot=camrot+3
if inkey$()="x" then camrot=camrot-3
rem camera distance from character
if mouseclick()=2
mymousey=mousemovey()
if mymousey>0 then camhgt=camhgt+3
if mymousey<0 then camhgt=camhgt-3
endif
rem raise - lower camera (mousewheel)
mymousez=mousemovez()
if mymousez>0 then camdist=camdist+5
if mymousez<0 then camdist=camdist-5
rem don't go below ground
if camhgt<0 then camhgt=0
return
rem camera update
update_camera:
rem Position camera to the back of the character
ca#=wrapvalue(a#+camrot)
cx#=newxvalue(x#,ca#,camdist)
cz#=newzvalue(z#,ca#,camdist)
if h2#>h#
cy#=h2#
else
cy#=h#
endif
position camera cx#,cy#+camhgt,cz#
rem Point camera at walker position
point camera x#,cy#+camlen,z#
return
rem reset camera
Resetcam:
set camera range 10,40000
camdist=-260
camhgt=80
camrot=0
camlen=0
rem --- check ground -----
heightcheck:
rem check the height at player position (X & Z)
h#=get ground height(1,x#,z#)
rem check the height at camera position
h2#=get ground height(1,cx#,cz#)
return
rem *********COLLISION**********
checkcoll:
collx#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#+20,h#+5,z#)
if collx#>0 then x#=x#-(20-collx#)
collz#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#,h#+5,z#+20)
if collz#>0 then z#=z#-(20-collz#)
collx2#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#-20,h#+5,z#)
if collx2#>0 then x#=x#+(20-collx2#)
collz2#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#,h#+5,z#-20)
if collz2#>0 then z#=z#+(20-collz2#)
return
end
45 degrees:
Rem * Title : Chafari Collision Concept
Rem Scorpyo - 2008
top:
rem ********** MAIN 1 ****************
set display mode 1024,768,32
hide mouse
sync on
sync rate 60
backdrop on
global x#,z#,h#,s#,a#
x#=10000.0:h#=0.0:z#=10000.0:turn=0
gosub Makematrix
gosub setambience
gosub Character
gosub makecube
set global collision off
gosub Resetcam
sync rate 60
rem *****MAIN LOOP******
do
if inkey$()="r" then x#=10000.0:z#=10000.0:s#=0.0
if inkey$()="e" then sync rate 0
if inkey$()="E" then sync rate 40
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
gosub Playercontrol
gosub printdata
rem call to camera changes subroutine ( bottom key row )
gosub camera_controls
rem terrain height check
gosub heightcheck
gosub checkcoll
position object 9999,x#,h#,z#
yrotate object 9999,a#
rem calls camera update subroutine
gosub update_camera
rem Update screen
sync
rem End loop
loop
rem ****** CREATE LEVEL ******
Makematrix:
rem create ground texture
cls rgb(0,100,20)
get image 2,0,0,250,250
rem Make landscape
landsize=23000:grid=30:mtxrandomize=1
make matrix 1,landsize,landsize,grid,grid
set matrix 1,1,0,0,1,1,1,1
prepare matrix texture 1,2,1,1
randomize matrix 1,mtxrandomize
rem ***********
rem get ground done
update matrix 1
return
setambience:
rem Create fog and ambience
set ambient light 80
if fog available()=1
fog on
fog distance 100000
fog color rgb(150,150,255)
endif
return
rem make object
makecube:
make object cube 1000,800
set object 1000,1,1,0,1,1,1,1
yrotate object 1000,45
position object 1000,10000,-200,10700
color object 1000,rgb(120,10,10)
return
printdata:
set cursor 0,0
rem set text opaque
rem debug check
print "Fps=",screen fps()
print "polygons=",statistic(1)
print "------player data-------"
print "x#= ",x#
print "z#= ",z#
print "player ground height h#= ",h#
print "camera ground height h2#= ",h#
print "angle#= ",a#
print "speed#= ",s#
print "---------------------------"
print "---------------------------"
print "press r to reset position"
print "W & S = walk"
print "mousemove x = turn"
print "mouse wheel = change camera distance from player"
print "R mouse + mouse move y = change camera height"
print "z and x rotate camera around the player"
return
Playercontrol:
rem ****Character walk ****
rem control walking with w and s keys
if inkey$()="w" and s#<5 then s#=s#+0.2
if inkey$()="s" and s#>-5 then s#=s#-0.2
rem control turning with mousemove along x axis
turn=mousemovex()
if turn<0 then a#=wrapvalue(a#-3)
if turn>0 then a#=wrapvalue(a#+3)
rem stop if "à" is pressed
if inkey$()="à" then s#=0.0
rem slow if "l"
if inkey$()="l" then s#=0.2
return
rem ****BUILD PLAYER****
rem object 9999
Character:
rem make cone
make object cone 9999,30
rem stretch cone
scale object 9999,100,300,100
rem tilt cone
xrotate object 9999,90
rem fix tilting angle
fix object pivot 9999
rem set object solid (no culling)
set object 9999,1,1,0
return
rem ********CAMERA ROUTINES***********
camera_controls:
rem reset intial camera pressing <
if inkey$()="<" then gosub Resetcam
rem camera views from high (m and M)
if inkey$()="m" then camdist=-1000:camhgt=500:set camera range 100,40000
if inkey$()="M" then camdist=-3000:camhgt=1000:set camera range 100,40000
rem look around (Right Mouse click + mouse move)
if inkey$()="z" then camrot=camrot+3
if inkey$()="x" then camrot=camrot-3
rem camera distance from character
if mouseclick()=2
mymousey=mousemovey()
if mymousey>0 then camhgt=camhgt+3
if mymousey<0 then camhgt=camhgt-3
endif
rem raise - lower camera (mousewheel)
mymousez=mousemovez()
if mymousez>0 then camdist=camdist+5
if mymousez<0 then camdist=camdist-5
rem don't go below ground
if camhgt<0 then camhgt=0
return
rem camera update
update_camera:
rem Position camera to the back of the character
ca#=wrapvalue(a#+camrot)
cx#=newxvalue(x#,ca#,camdist)
cz#=newzvalue(z#,ca#,camdist)
if h2#>h#
cy#=h2#
else
cy#=h#
endif
position camera cx#,cy#+camhgt,cz#
rem Point camera at walker position
point camera x#,cy#+camlen,z#
return
rem reset camera
Resetcam:
set camera range 10,40000
camdist=-260
camhgt=80
camrot=0
camlen=0
rem --- check ground -----
heightcheck:
rem check the height at player position (X & Z)
h#=get ground height(1,x#,z#)
rem check the height at camera position
h2#=get ground height(1,cx#,cz#)
return
rem *********COLLISION**********
checkcoll:
collx#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#+20,h#+5,z#)
if collx#>0 then x#=x#-(20-collx#)
collz#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#,h#+5,z#+20)
if collz#>0 then z#=z#-(20-collz#)
collx2#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#-20,h#+5,z#)
if collx2#>0 then x#=x#+(20-collx2#)
collz2#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#,h#+5,z#-20)
if collz2#>0 then z#=z#+(20-collz2#)
return
end