Hi all,
I have a character with a idle, walk and jump animation but something is not right.
First of all, here is the code (with the necessary files attached):
Rem Project: ANIM TEST
Rem Created: 6/9/2010 10:53:48 PM
Rem ***** Main Source File *****
SET DISPLAY MODE 1024, 768, 32
SYNC ON
SYNC RATE 60
HIDE MOUSE
`=================
`SETTING UP CAMERA
`=================
`Position Variables
GLOBAL camerax AS INTEGER = 0
GLOBAL cameray AS FLOAT = 20.0
GLOBAL cameraz AS FLOAT = -50.0
`Camera Lookat Variables
GLOBAL camerax_lookat AS INTEGER = 0
GLOBAL cameray_lookat AS FLOAT = 15.0
GLOBAL cameraz_lookat AS INTEGER = 0
`The Camera
MAKE CAMERA 1
POSITION CAMERA 1, camerax, cameray, cameraz
POINT CAMERA 1, camerax_lookat, cameray_lookat, cameraz_lookat
`==============
`THE LITTLE BOY
`==============
`Position and Control
GLOBAL playerx AS INTEGER = -10
GLOBAL playery AS INTEGER = 25
GLOBAL playerz AS INTEGER = 0
`Movement
GLOBAL player_speed AS FLOAT = 0.3
`Direction of Movement
GLOBAL left AS INTEGER = 0
GLOBAL right AS INTEGER = 1
GLOBAL yrotate AS INTEGER = 0
`Jumping
GLOBAL jump AS INTEGER = 0
GLOBAL jump_delay AS INTEGER = 0
GLOBAL jump_speed AS FLOAT = 1.0
GLOBAL rise_delay AS INTEGER = 0
`Animation
GLOBAL idle_anim AS INTEGER = 0
GLOBAL walk_anim AS INTEGER = 0
GLOBAL walk_toggle AS INTEGER = 0
GLOBAL jump_anim AS INTEGER = 0
GLOBAL jump_toggle AS INTEGER = 0
`The Player's Core
MAKE OBJECT CUBE 100, 1
POSITION OBJECT 100, playerx, playery, playerz
SC_SETUPOBJECT 100, 1, 1
HIDE OBJECT 100
`The Player's Body (Walk)
LOAD OBJECT "boy.x", 101
POSITION OBJECT 101, playerx, playery, playerz
`=================
`SETTING UP GROUND
`=================
`Ground 1
LOAD OBJECT "l_platform.x", 10
POSITION OBJECT 10, 0, 0, 0
SC_SETUPOBJECT 10, 2, 2
`============
`MAIN DO LOOP
`============
DO
SC_UPDATEOBJECT 100
SC_UPDATEOBJECT 10
`Player's Body
POSITION OBJECT 101, OBJECT POSITION X(100), OBJECT POSITION Y(100) + 1, OBJECT POSITION Z(100)
`==============
`WOLD FUNCTIONS
`==============
gravity()
camera()
controls()
TEXT 0, 0, "walk_anim: " +str$(walk_anim)
TEXT 0, 20, "walk_toggle: " +str$(walk_toggle)
TEXT 200, 0, "jump: " +str$(jump)
TEXT 200, 20, "jump_anim: " +str$(jump_anim)
TEXT 200, 40, "jump_toggle: " +str$(jump_toggle)
TEXT 400, 00, "idle_anim: " +str$(idle_anim)
SYNC
LOOP
FUNCTION gravity()
`If the player is not jumping or is not standing on anything, make him fall down
IF jump = 0 AND SC_GROUPCOLLISION(100, 2) = 0
MOVE OBJECT DOWN 100, player_speed
SET OBJECT FRAME 101, 60
ENDIF
ENDFUNCTION
FUNCTION camera()
`NOTE: The formula for Camera is "cameray = The main ground platform + 25"
`The Camera and the Camera's Lookat following the player's X position
POSITION CAMERA 1, OBJECT POSITION X(100), cameray, cameraz
POINT CAMERA 1, OBJECT POSITION X(100), cameray_lookat, 0
ENDFUNCTION
`======================================================================================================================================
` PLAYER FUNCTIONS
`======================================================================================================================================
FUNCTION controls()
`======================
`PLAYER WHEN HE IS IDLE
`======================
IF walk_anim = 0 AND jump_anim = 0
idle_anim = 1
ELSE
idle_anim = 0
ENDIF
IF idle_anim = 1
LOOP OBJECT 101, 61, 101
ENDIF
`===========================
`MOVING PLAYER LEFT OR RIGHT
`===========================
IF RIGHTKEY() = 1 AND LEFTKEY() = 0
MOVE OBJECT RIGHT 100, player_speed
left = 0
right = 1
yrotate = 0
ENDIF
IF LEFTKEY() = 1 AND RIGHTKEY() = 0
MOVE OBJECT LEFT 100, player_speed
left = 1
right = 0
yrotate = 180
ENDIF
`Playing walking animation
IF LEFTKEY() = 1 OR RIGHTKEY() = 1 AND jump = 0
walk_anim = 1
ENDIF
IF LEFTKEY() = 0 AND RIGHTKEY() = 0
walk_anim = 0
walk_toggle = 0
ENDIF
IF walk_anim = 1 AND walk_toggle = 0
LOOP OBJECT 101, 0, 32
walk_toggle = 1
ENDIF
IF walk_anim = 0
SET OBJECT FRAME 101, 0
ENDIF
ROTATE OBJECT 101, 0, yrotate, 0
SET OBJECT SPEED 101, 35
`===========================
`ALLOWING THE PLAYER TO JUMP
`===========================
`Initiating the jump
IF jump = 0 AND SPACEKEY() = 1 AND SC_GROUPCOLLISION(100, 2) > 0
jump = 1
jump_speed = 1.0
jump_delay = 3
SCALE OBJECT 101, 110, 80, 100
POSITION OBJECT 100, OBJECT POSITION X(100), OBJECT POSITION Y(100) - 0.5, OBJECT POSITION Z(100)
ENDIF
`Controlling the speed of the jump
IF jump = 1 AND rise_delay = 0
rise_delay = 5
DEC jump_speed, 0.2
ENDIF
`Causing the player to jump
IF jump = 1 AND jump_delay = 0
MOVE OBJECT UP 100, jump_speed
SCALE OBJECT 101, 100, 100, 100
ENDIF
`Playing jumping animation
IF jump = 1
jump_anim = 1
ENDIF
IF jump = 0
jump_anim = 0
jump_toggle = 0
walk_toggle = 0
ENDIF
IF jump_anim = 1 AND jump_toggle = 0
PLAY OBJECT 101, 33, 60
jump_toggle = 1
ENDIF
`==================
`LANDING THE PLAYER
`==================
`Landing the player on any Platforms
IF jump = 1 AND jump_speed < 0 AND OBJECT COLLISION(100, 10) = 1
jump = 0
jump_speed = 0.0
POSITION OBJECT 100, OBJECT POSITION X(100), OBJECT POSITION Y(10) + 1.5, OBJECT POSITION Z(100)
ENDIF
`Jumping delays
IF jump_delay > 0
DEC jump_delay, 1
ENDIF
IF rise_delay > 0
DEC rise_delay, 1
ENDIF
ENDFUNCTION
When you walk the character left or right, he plays the walk animation and when you "jump from a walk" he plays the jump animation.
However, if he stands still, he doesn't play his idle animation and if you jump from an idle position (i.e. without moving) then his jump animation won't play.
I can't figure out why it doesn't want to play his idle and jump animation. I thought it was because maybe I done the keyframes wrong. But if I replaced the walk keyframes with the idle keyframes, then the character will move while playing his idle animation. So the keyframes are all correct.
Can anyone figure this out?
BTW, here is the list of animation:
Walk: 0 - 32
Jump: 33 - 60
Idle: 61 - 101