OK. Hope this is useful. I has some mistakes in my code suggestion above, but this works. If you have questions about this ask.
Rem Project: cowbox movement
Rem Created: 18/07/2007 16:47:07
Rem ***** Main Source File *****
`smooth 8-way directional movement for Recre john
sync on:sync rate 60
autocam off:position camera 0,100,0:point camera 0,0,0
obj=1
`create an object to move around. A cone pointed "forwards"
make object cone 1,10:xrotate object 1,90
make mesh from object 1,1:delete object 1:make object obj,1,0:delete mesh 1
`key define..
dim options(2)
options(1)=1 `arrow keys
if OPTIONS(1)=1 then UP=200 : LEFT=203 : DOWN=208 : RIGHT=205
if OPTIONS(1)=2 then UP=17 : LEFT=30 : DOWN=31 : RIGHT=32
if OPTIONS(1)=3 then UP=23 : LEFT=36 : DOWN=37 : RIGHT=38
dim myinfo$(5)
`MOVEMENT TYPE INFORMATION
`1
myinfo$(1)="original code"
`in original code, if press a diagonal, will walk faster than if moving up/down/left/right
`2
myinfo$(2)="corrected 8-way rotation"
`more efficient code than 0, which should have exactly the same movement,
`but with corrected player rotation.
`3
myinfo$(3)="corrected 8-way rotation, same speed all directions"
`in original code, if press a diagonal, will walk faster than if moving up/down/left/right
`for constant speed movement irrespective of direction, and with corrected player rotation,
`NB if you use type 2, then the game will play a bit differently and it is possible that
`some things involving diagonal movement are not doable any more...
`4
myinfo$(4)="smooth turning verison of type 2"
`5
myinfo$(5)="smooth turning verison of type 3"
`note that two angles are used. Angle2 is smoothed angle and used to determine player rotation.
movement_type=1 `initial setting
turn_smoothing#=5.0 `experiment with this value. higher value= slower response
do
`SWITCHING BETWEEN TYPES AND DISPLAY TEXT
if keystate(2) then movement_type=1
if keystate(3) then movement_type=2
if keystate(4) then movement_type=3
if keystate(5) then movement_type=4
if keystate(6) then movement_type=5
text 0,0,"Press number keys 1-5 to change movement type"
text 0,10,"MOVEMENT TYPE="+str$(movement_type)
text 0,20,myinfo$(movement_type)
`MOVEMENT
select movement_type
case 1
`original code
if keystate(UP) then yrotate object OBJ,0 : move object OBJ,1
if keystate(DOWN) then yrotate object OBJ,180 : move object OBJ,1
if keystate(LEFT) then yrotate object OBJ,-90 : move object OBJ,1
if keystate(RIGHT) then yrotate object OBJ,90 : move object OBJ,1
endcase
case 2
`this part does the same as above, probably slightly more efficient
upmove=keystate(UP)-keystate(DOWN)
rightmove=keystate(RIGHT)-keystate(LEFT)
yrotate object OBJ,0 : move object OBJ,upmove
yrotate object OBJ,90 : move object OBJ,rightmove
`this part works out what rotation to use
if upmove or rightmove
angle=atanfull(rightmove,upmove)
endif
yrotate object OBJ,angle
endcase
case 3
upmove=keystate(UP)-keystate(DOWN)
rightmove=keystate(RIGHT)-keystate(LEFT)
if upmove or rightmove
angle=atanfull(rightmove,upmove)
yrotate object OBJ,angle
move object OBJ,1
endif
endcase
case 4
upmove=keystate(UP)-keystate(DOWN)
rightmove=keystate(RIGHT)-keystate(LEFT)
yrotate object OBJ,0 : move object OBJ,upmove
yrotate object OBJ,90 : move object OBJ,rightmove
if upmove or rightmove
angle#=curveangle(atanfull(rightmove,upmove),angle#,turn_smoothing#)
endif
yrotate object OBJ,angle#
endcase
case 5
upmove=keystate(UP)-keystate(DOWN)
rightmove=keystate(RIGHT)-keystate(LEFT)
if upmove or rightmove
angle#=atanfull(rightmove,upmove)
angle2#=curveangle(angle#,angle2#,turn_smoothing#)
yrotate object OBJ,angle#
move object OBJ,1
yrotate object OBJ,angle2#
endif
endcase
endselect
sync
loop