Try this out:
Rem Project: Dark Basic Pro Project
Rem Created: Thursday, January 30, 2014
rem Author: Shellfish Games
Rem ***** Main Source File *****
set display mode 1280,800,32,1
sync on : sync rate 60 : sync
hide mouse
make matrix 1, 100,100, 40,40
position matrix 1, -50, -2, -50
for i = 1 to 200
make object cube i, 1
position object i, rnd(50) - rnd(50), rnd(10) - rnd(10), rnd(50) - rnd(50)
next
position camera 0, 0,0,0
point camera 0, 0,0,1
xangle# = 0
yangle# = 0
xp# = 0
yp# = 0
zp# = 0
angp# = 0.0
angp_target# = 0.0
xoff# = 0
yoff# = 0.4
zoff# = 0
do
rem Look
inc xangle#, mousemovey()*0.2
inc yangle#, mousemovex()*0.2
if xangle# > 90.0 then xangle# = 90.0 else if xangle# < -90.0 then xangle# = -90.0 `<- locking the angle
xrotate camera 0, xangle#
yrotate camera 0, yangle#
rem Move
fw = keystate(17) - keystate(31)
rl = keystate(32) - keystate(30)
if fw or rl or angp# < angp_target#
rem Actual Camera position (without walking animation)
inc xp#, 0.1*(fw*sin(yangle#) + rl*sin(yangle#+90))
inc zp#, 0.1*(fw*cos(yangle#) + rl*cos(yangle#+90))
rem Walking Animation
inc angp#, 4.0 `<- animation speed
rem Camera Offset (added to actual camera position to achieve walking animation)
xoff# = 0.6*sin(yangle#+90)*sin(angp#)
zoff# = 0.6*cos(yangle#+90)*sin(angp#)
yoff# = 0.3*sin(2*angp#+90)
if fw or rl
rem Active Movement -> Keep Walking Animation Going
angp_target# = 180*(int(angp#) / 180) + 180 `next
else
rem No active Movement -> just finish walking animation
if angp# > angp_target# then angp# = angp_target#
endif
endif
position camera 0, xp#+xoff#,yp#+yoff#,zp#+zoff#
rem Info
set cursor 0,0
print "FPS: ", screen fps()
print
print "Press WASD to Move"
print "Move Mouse to Look Around"
sync
loop
I tried to explain everything in the code, but if something's unclear just ask. The method is actually really simple - you just separate the actual camera position from an offset which is responsible for the animation. The rest is a bit trigonometry and tweaking of the values and angles.