EDIT: I'm removing the downloads because they contain models from the Game Creators Store.
Alright, I've scrapped my last FPS project because it was becoming a large, semi-functional mess. I've decided to not even look at a shader this time until the actual game elements are done. It's going to be an endurance shooter like Nazi Zombies/Firefight/Horde or whatever. This is the first time I've tried to get an animated model working, and I've actually made some progress with it. Unfortunately, I didn't make enough progress with it.
I can either get the gun to display an idle animation while standing still, and a bobbing animation while moving; or I can get it to display a firing animation.
Anyways, Code:
`Basic Setup
SET WINDOW TITLE "Survival"
SET WINDOW OFF
SET DISPLAY MODE 1280,1024,32
SYNC ON
SYNC RATE 60
HIDE MOUSE
AUTOCAM OFF
PHY START
LOAD OBJECT "MAP.DBO",9999
PHY MAKE RIGID BODY STATIC MESH 9999
MAKE OBJECT BOX 1,25,2,25
POSITION OBJECT 1,0,5,0
HIDE OBJECT 1
PHY MAKE BOX CHARACTER CONTROLLER 1,0,5,0,12.5,1,12.5,1,5,45
`Aiming Object
MAKE OBJECT CUBE 9998,2
HIDE OBJECT 9998
`Aiming Limb
MAKE OBJECT SPHERE 9997,2
MAKE MESH FROM OBJECT 1,9997
DELETE OBJECT 9997
ADD LIMB 9998,1,1
OFFSET LIMB 9998,1,0,0,500
HIDE LIMB 9998,1
`Test Enemy
MAKE OBJECT SPHERE 2,50
COLOR OBJECT 2,RGB(255,000,000)
POSITION OBJECT 2,0,50,300
LOAD OBJECT "GUN/HUD.X",7
LOAD SOUND "GUN/FIRE.WAV",7
SET OBJECT CULL 7,0
YROTATE OBJECT 7,180
LOCK OBJECT ON 7
POSITION OBJECT 7,5,0,15
LOOP OBJECT 7,10,38
DISABLE OBJECT ZDEPTH 7
`Variables
EnemyHP#=100
Ammo#=12
MaxAmmo#=12
DO
`Animate Gun
IF KEYSTATE(17) OR KEYSTATE(30) OR KEYSTATE(31) OR KEYSTATE(32)=1
LOOP OBJECT 7,39,61
ELSE
LOOP OBJECT 7,10,38
ENDIF
POSITION MOUSE SCREEN WIDTH()/2,SCREEN HEIGHT()/2
TEXT 10, 20, "Frames Per Second: " + STR$(SCREEN FPS())
TEXT 10, 40, "X-Pos: " + STR$(OBJECT POSITION X(1))
TEXT 10, 60, "Y-Pos: " + STR$(OBJECT POSITION Y(1))
TEXT 10, 80, "Z-Pos: " + STR$(OBJECT POSITION Z(1))
`Keep Mouse Centered
POSITION MOUSE SCREEN WIDTH()/2,SCREEN HEIGHT()/2
`Positoin Camra Over Player Object
POSITION CAMERA OBJECT POSITION X(1),OBJECT POSITION Y(1)+70,OBJECT POSITION Z(1)
`Position Aiming Object On The Camera
POSITION OBJECT 9998, CAMERA POSITION X(),CAMERA POSITION Y(),CAMERA POSITION Z()
CAMY#=CAMY#+MOUSEMOVEX()*.2
CAMX#=CAMX#+MOUSEMOVEY()*.2
YROTATE CAMERA CAMY#
XROTATE CAMERA CAMX#
YROTATE OBJECT 1,CAMY#
YROTATE OBJECT 9998,CAMY#
xROTATE OBJECT 9998,CAMX#
IF WRAPVALUE(CAMERA ANGLE X(0))>60 AND WRAPVALUE(CAMERA ANGLE X(0))<180 then XROTATE CAMERA 0,60
IF WRAPVALUE(CAMERA ANGLE X(0))>180 AND WRAPVALUE(CAMERA ANGLE X(0))<280 then XROTATE CAMERA 0,280
IF WRAPVALUE(OBJECT ANGLE X(9998))>60 AND WRAPVALUE(OBJECT ANGLE X(9998))<180 then XROTATE OBJECT 9998,60
IF WRAPVALUE(OBJECT ANGLE X(9998))>180 AND WRAPVALUE(OBJECT ANGLE X(9998))<280 then XROTATE OBJECT 9998,280
`Simple Firing Code
Wait# = 700 : `milliseconds
if Timer() - OldTime > Wait#
IF MOUSECLICK()=1
IF Ammo#>0
DEC Ammo#,1
PLAY OBJECT 7,62,74
PLAY SOUND 7
IF OBJECT EXIST(2)=1
IF Ammo#>0 AND INTERSECT OBJECT (2, LIMB POSITION X(9998,1), LIMB POSITION Y(9998,1), LIMB POSITION Z(9998,1), OBJECT POSITION X(9998),OBJECT POSITION Y(9998), OBJECT POSITION Z(9998))>0 THEN DEC EnemyHP#,10
endif
OldTime = Timer()
ENDIF
ENDIF
endif
`Kill Enemy Code
IF EnemyHP#=0 AND OBJECT EXIST(2)=1 THEN DELETE OBJECT 2
IF KEYSTATE(19)=1 AND Ammo#=0 THEN Ammo#=MaxAmmo#
`Ammo Counter and Crosshair
TEXT 0,SCREEN HEIGHT()-50,"Ammo: "+str$(Ammo#)
CIRCLE SCREEN WIDTH()/2,SCREEN HEIGHT()/2,5
`Movement Variables
PPX# = OBJECT POSITION X(1)
PPY# = OBJECT POSITION Y(1)
PPZ# = OBJECT POSITION Z(1)
PAX# = OBJECT ANGLE X(1)
PAY# = OBJECT ANGLE Y(1)
PAZ# = OBJECT ANGLE Z(1)
IF KEYSTATE(17)
PHY MOVE CHARACTER CONTROLLER 1,180
ELSE
PHY MOVE CHARACTER CONTROLLER 1,0
ENDIF
IF KEYSTATE(31)
PHY MOVE CHARACTER CONTROLLER 1,-180
ELSE
PHY MOVE CHARACTER CONTROLLER 1,0
ENDIF
IF KEYSTATE(30)
YROTATE OBJECT 1,PAY#+90
PHY MOVE CHARACTER CONTROLLER 1,-180
YROTATE OBJECT 1,PAY#
ELSE
PHY MOVE CHARACTER CONTROLLER 1,0
ENDIF
IF KEYSTATE(32)
YROTATE OBJECT 1,PAY#-90
PHY MOVE CHARACTER CONTROLLER 1,-180
YROTATE OBJECT 1,PAY#
ELSE
PHY MOVE CHARACTER CONTROLLER 1,0
ENDIF
PHY MOVE CHARACTER CONTROLLER 1,.1
PHY MOVE CHARACTER CONTROLLER 1,-.1
PHY UPDATE
SYNC
LOOP
My 2 different animation codes are:
`Animate Gun
IF KEYSTATE(17) OR KEYSTATE(30) OR KEYSTATE(31) OR KEYSTATE(32)=1
LOOP OBJECT 7,39,61
ELSE
LOOP OBJECT 7,10,38
ENDIF
and in my firing code:
Wait# = 700 : `milliseconds
if Timer() - OldTime > Wait#
IF MOUSECLICK()=1
IF Ammo#>0
DEC Ammo#,1
PLAY OBJECT 7,62,74
PLAY SOUND 7
IF OBJECT EXIST(2)=1
IF Ammo#>0 AND INTERSECT OBJECT (2, LIMB POSITION X(9998,1), LIMB POSITION Y(9998,1), LIMB POSITION Z(9998,1), OBJECT POSITION X(9998),OBJECT POSITION Y(9998), OBJECT POSITION Z(9998))>0 THEN DEC EnemyHP#,10
endif
OldTime = Timer()
ENDIF
ENDIF
endif
If I comment out the
`Animate Gun
IF KEYSTATE(17) OR KEYSTATE(30) OR KEYSTATE(31) OR KEYSTATE(32)=1
LOOP OBJECT 7,39,61
ELSE
LOOP OBJECT 7,10,38
ENDIF
section, then the firing animation works fine, but the movement animation of course won't play. If they're both active (not commented out) then the movement animation seems to work, but the firing animation won't work.
Attatched is the media and project file if you need to mess about with it to get it working.
I'll also probably need help getting the reload animation to work.
Thanks for any help you can provide.