Here is a slightly modified code from the code snippets board. From Phaelax I believe. It allows the user to walk up and down the terrain at almost the same angle as the terrain. So you walk up hills slower than flat areas insted of the opposite
sync on : sync rate 0
hide mouse : autocam off
make matrix 1,500,500,50,50
randomize matrix 1, 10
update matrix 1
position camera 250,25,250
do
`mouselook code
rotate camera camera angle x()+(mousemovey()/2),camera angle y()+(mousemovex()/2),0
cx#=camera angle x() : cy#=camera angle y() : cz#=camera angle z()
if camera angle x()>90 then xrotate camera 90
if camera angle x()<-90 then xrotate camera -90
cx#=camera angle x()
`move player forward/back and/or strafe
`if spacekey is pressed don't use matrix angle correction while moving
`this mackes it rough and it makes you move faster because you are
`walking through the ground then being raised or lower to equal it height
`Without spacekey pressed it checks the matrix angle
`and makes the camera follow it to some ectent.
if spacekey() = 0
if upkey()=1 then xrotate camera playerterrainangle# : move camera .1 : xrotate camera cx#
if downkey()=1 then xrotate camera playerterrainangle# : move camera -.1 : xrotate camera cx#
else
if upkey()=1 then xrotate camera 0 : move camera .1 : xrotate camera cx#
if downkey()=1 then xrotate camera 0 : move camera -.1 : xrotate camera cx#
endif
`strafing code
if leftkey()=1 then yrotate camera cy#-90 : move camera .11 : yrotate camera cy#
if rightkey()=1 then yrotate camera cy#-90 : move camera -.11 : yrotate camera cy#
`update camera positions
c_p_x#=camera position x() : c_p_y#=camera position y() : c_p_z#=camera position z()
`update ground positions
GroundLevel# = get ground height(1,c_p_x#,c_p_z#)+5
`get the terrain angle
playerterrainangle# = tilt(1,c_p_x#, c_p_z#, cy#,GroundLevel#)
`put camera at groung height as angle checking isn't perfect
position camera c_p_x#, GroundLevel#, c_p_z#
`draw crosshair on screen
circle screen width()/2,screen height()/2,8
`make changes to the screen
sync
loop
`get the angle of matrix where you are walking
function tilt(matrixnumber as integer,tilttestx# as float, tilttestz# as float, tilttestangle# as float, h1# as float)
`h1# = get matrix ground height(matrixnumber,tilttestx#,tilttestz#)
b# = 1
tx#=newxvalue(tilttestx#,tilttestangle#,.1)
tz#=newzvalue(tilttestz#,tilttestangle#,.1)
h2# = get ground height(matrixnumber,tx#,tz#)
at# = h2# - h1#
angx# = 0-atan(at#/b#)
endfunction angx#