rem Scene setup
sync rate 60 : sync on
make matrix 1,64,64,64,64
make object box 1,4,7,2
rem Main Loop
do
rem Are any keys being pressed?
if upkey() or downkey() or leftkey() or rightkey()
rem Get the angle of the keys, and add the camera angle.
targetangle#=atanfull(rightkey()-leftkey(),upkey()-downkey())+camangle#
rem This angle is then smoothed to prevent jerkiness. 5 is how many frames turning should take.
angle#=curveangle(targetangle#,angle#,5)
rem Apply the angle to the character.
yrotate object 1,angle#
rem Smooth acceleration. 0.2 is the speed, 5 is how long it should take.
speed#=curvevalue(0.2,speed#,5)
rem Turn the camera if the player is going left or right.
inc targetcamangle#,sin(targetangle#-camangle#)
rem Is down being pressed?
if downkey()
rem Was it being pressed last frame?
if antirep=0
rem If only downkey is being pressed, do a 180 spin.
if leftkey()=0 and rightkey()=0 and upkey()=0
inc targetcamangle#,180
endif
rem Prevent repeat spins.
antirep=1
endif
else
rem if the downkey isn't being pressed, reset antirep.
antirep=0
endif
else
If the player's not moving, do gentle slowdown. 5 is how many frames it takes to stop.
speed#=curvevalue(0.0,speed#,5)
endif
rem Smooth the camera. No jerkiness.
camangle#=curvevalue(targetcamangle#,camangle#,25)
Rem This is essentially move object.
position object 1,object position x(1)+(sin(angle#)*speed#),0,object position z(1)+(cos(angle#)*speed#)
Rem position the camera. 16 is the distance and 4 is the height.
position camera object position x(1)-(sin(camangle#)*16),4,object position z(1)-(cos(camangle#)*16)
Rem Point the camera above the player's head.
point camera object position x(1),3,object position z(1)
sync
loop
By putting a signpost in the middle of nowhere, you're making it somewhere.