Ok I managed to get some code going that seems to work well.
I did what Ortu said and used the keystates to set a flag which then jumped to a routine that played the relevant animation and moved the object before setting the flag to off before the next cycle.
Rem ***** Main Source File *****
Rem Project: FRagem2
Rem Created: Saturday, January 11, 2014
Rem ***** Main Source File *****
sync on
sync rate 60
autocam off
set camera range 0.5, 100000
hide mouse
set ambient light 30
map=1
skybox=2
player1=3
player2=4
playercolisionbox=5
gun1=6
player1helper=7
mapimage=1
player1texture=2
player2texture=3
gun1image=4
movingoff=1
framespeed=40
player1speed#=0.5
load object "map1.x",map
load image "texture.bmp",mapimage
texture object map,mapimage
position object map,0,0,0
`****************************** Create Skybox
load object "skybox2.x",skybox
set object light skybox, 0
set object texture skybox, 3, 0
position object skybox, 1000,0, 4000
scale object skybox, 30000, 30000, 30000
`****************************** Create Player 1
load object "player.x",player1
load image "playercanada.dds",player1texture
scale object player1,12,12,12
texture object player1,player1texture
position object player1,0,-5,10
set object speed player1,40
fra= total object frames(player1)
set object cull player1,0
`loop object player1,1490,1513
`******************************** Create Gun
load object "gun.x",gun1
load Image "gun.dds",gun1image
zrotate object gun1,90
xrotate object gun1,-90
fix object pivot gun1
position object gun1,0,0,5
` ****************** make gun into limb and attatch to players hand
make mesh from object 1,gun1
add limb player1,72,1
texture limb player1,72,gun1image
link limb player1,33,72
delete object gun1
delete mesh 1
`****************** create player 1 helper object for collision detection
make object sphere player1helper,10
make mesh from object 1,player1helper
position object player1helper,0,3,58
`GHOST OBJECT ON player1helper,1
hide object player1helper
add limb player1helper,1,1
offset limb player1helper,1,0,0,10
scale limb player1helper,1,100,100,100
link limb player1helper,0,1
`hide limb player1,73
do
gosub Info
gosub player1lookupdate
gosub player1move
sync
loop
end
player1lookupdate:
`*********************************** outside view ******
` position camera object position x(player1),object position y(player1)+5,object position z(player1)+15
`********************************** follow view *******************
position camera LIMB POSITION x(player1helper,1),limb position y(player1helper,1),LIMB POSITION z(player1helper,1)
`********************************************************
point camera object position x(player1helper),object position y(player1helper), object position z(player1helper)
SET OBJECT TO OBJECT ORIENTATION player1,player1helper
position object player1,object position x(player1helper),object position y(player1helper)-5, object position z(player1helper)
Oldplayer1AngleY# = player1AngleY#
Oldplayer1AngleX# = player1AngleX#
player1AngleY# = wrapvalue ( player1AngleY# + mousemovex ( ) * 0.4 )
player1AngleX# = wrapvalue ( player1AngleX# + mousemovey ( ) * 0.4 )
yrotate object player1helper,curveangle( player1AngleY#,Oldplayer1AngleY#, 24 )
xrotate camera curveangle ( player1AngleX#, Oldplayer1AngleX#, 24 )
return
player1move:
if keystate(17) then forward=1 `forward
if keystate(31) then backward=1 `backwards
if keystate(30) then right=1 `stride right
if keystate(32) then left=1 `stride left
if keystate(17) and keystate(32) then forwardright=1
if keystate(17) and keystate(30) then forwardleft=1
if keystate(31) and keystate(30) then backwardright=1
if keystate(31) and keystate(32) then backwardleft=1
if forward=0 and backward=0 and right=0 and left=0 and forwardright=0 and forwardleft=0 and backwardright=0 and backwardleft=0 then idle=1
if idle=1
SET OBJECT SPEED player1,framespeed/3
loop object player1,3722,3777
`loop object player1,1490,1513
idle=0
endif
if forwardright=1 `Forwards and Right
move object player1helper,-player1speed#/6
move object left player1helper,player1speed#/6
SET OBJECT SPEED player1,framespeed
loop object player1,1560,1578
gosub setmoveto0
endif
if forwardleft=1 `Forwards and Left
move object right player1helper,player1speed#/6
move object player1helper,-player1speed#/6
SET OBJECT SPEED player1,framespeed
loop object player1,1540,1559
gosub setmoveto0
endif
if backwardleft=1 `Backward and Left
move object left player1helper,player1speed#/6
move object player1helper,player1speed#/6
SET OBJECT SPEED player1,framespeed/2
loop object player1,1560,1578
gosub setmoveto0
endif
if backwardright=1 `Backward and Right
move object right player1helper,player1speed#/6
move object player1helper,player1speed#/6
SET OBJECT SPEED player1,framespeed/2
loop object player1,1540,1559
gosub setmoveto0
endif
if forward=1 `forward
move object player1helper,-player1speed#
SET OBJECT SPEED player1,framespeed
loop object player1,1970,1986
gosub setmoveto0
endif
if backward=1 `backwards
move object player1helper,player1speed#/6
SET OBJECT SPEED player1,-framespeed/2
loop object player1,1970,1986
gosub setmoveto0
endif
if right=1 `stride right
move object right player1helper,player1speed#/5
SET OBJECT SPEED player1,framespeed
loop object player1,1540,1559
gosub setmoveto0
endif
if left=1 `stride left
move object left player1helper,player1speed#/5
SET OBJECT SPEED player1,framespeed
loop object player1,1560,1578
gosub setmoveto0
endif
return
setmoveto0:
forwardright=0
forward=0
backward=0
right=0
left=0
forwardright=0
forwardleft=0
backwardleft=0
backwardright=0
return
Info:
SET CURSOR 0,10
Print "Player 1 Position X Coordinates " + Str$(object position x(Player1))
Print "Player 1 Position z Coordinates " + Str$(object position z(Player1))
print "fps = " + str$ ( screen fps ( ) )
Print "PLayer 1 Frame" +STR$(fra)
return
"There are no perfect ideas only perfect intentions"