Well, the simple method would be to have a speed variable to control the player speed, this would do it pretty smoothly, but you'll have to mess with it to get it nice for your particular game.
Player_walking:
stage=0
`*** The spd# should be 10 as a default
`Slow down the speed to a walk
if stage=0 and spd#>10 and shiftkey()=0 then dec spd#,0.1
`Set the animation speed to match, multiply it by something until it works!
set object speed playerobj,spd#
if upkey()=1
`Speed up to running speed
if shiftkey()=1 and spd#<15.0 then inc spd#,0.2
x#=newxvalue(x#,cya#,10.0) : z#=newzvalue(z#,cya#,spd#)
stage=1
endif
if downkey()=1
x#=newxvalue(x#,cya#,-10.0) : z#=newzvalue(z#,cya#,-10.0)
stage=1
endif
if stage=0 and spd#>10 then dec spd#,0.1
if leftkey()=1
x#=newxvalue(x#,wrapvalue(cya#-90.0),6.0)
z#=newzvalue(z#,wrapvalue(cya#-90.0),6.0)
endif
if rightkey()=1
x#=newxvalue(x#,wrapvalue(cya#+90.0),6.0)
z#=newzvalue(z#,wrapvalue(cya#+90.0),6.0)
endif
rem Aquire ground height of new position
y#=get ground height(1,x#+mx#,z#+mz#)
if y#<-50.0 then y#=-50.0
rem Walk Height angle
if stage=1
walkha#=wrapvalue(walkha#+16.0)
else
walkha#=curveangle(0.0,walkha#,5.0)
endif
walkh#=(cos(walkha#)*4.5)
Return
The toughest thing to get smooth is the player animation, here's a good method for smooth integration.
* Split the animation into sets, sets 1 to 3 are for walking, sets 4 to 6 are running, like:
Set 1 - Standing still to walking.
Set 2 - Walking loop.
Set 3 - Walking to standing still.
Set 4 - Standing still to Running.
Set 5 - Running loop.
Set 6 - Running to standing still.
Now, the idea is you start at set 1, and if at the end of set 2 the player is still walking, you reset the frame to the start of set 2 again, if you stopped walking then the player slows down to a halt. This would give nice professional movement. You can simply replace the sets for when the run key is pressed, but only change to the running set when looping the animation - it'll look smooth as silk if your careful with the running to walking transitions. To use this method, it's best to apply the speed to the positions outside of the control conditions, so the keys adjust variables like angle and speed, and all the movement is independent, this will allow gradual stops using the animations properly too - because the speed can slow down to a crawl, or you can just set the speed to 0 when the frame gets passed the last set and it's left in the standing pose.
Van-B
My cats breath smells of cat food.