Manipulating .B3D character animations

Blitz3D Forums/Blitz3D Beginners Area/Manipulating .B3D character animations

Hey guys,

I've been trying to get .B3D character animations to work properly for a few days and i'm having a lot of trouble.

Basically i'm using a Mario character (taken fron Sinu's great 3D Mario demo from a few years ago) and I simply want to use the idle state for when he's idle, the walk state for when the player moves the character etc.

The problem i'm having is when I move the character the animations stops. Here's an example of the code I wrote:

If CharX > 0.02 Then Animate Dude, 1, 0.46, 2, 12

If Not Animating (Dude) Then
    Animate Dude, 1, 0.46, 1, 12
End If


I'm also trying to control the animation speed by feeding the characters X speed into the animation speed variable but that just seems to freeze the animation entirely.

If anyone has tips or can spot what i'm doing wrong it would be very much appreciated :-)

1. Use Animation States. This means that you set a state walking = true or movementState = walking on charx > 0.02 for example and then
if movementState = walking and <if animation xy is not playing> animate ....

yours will restart the animation whenever charx > 0.02 which obviously means that you will never leave the initial frame.

ok i'm completely stumped now, everything I do seems to get stuck on the first frame of the animation. I've tried so many different options and all it's done is confuse me ;-)

Anyway here's my complete code, please excuse the mess:

; 3D MODEL VIEWER

;------------------------------------------------------
; INITIAL SETUP
;------------------------------------------------------

Graphics3D 800,600,0,2
SetBuffer BackBuffer ()

AppTitle "Character Animation Test"

;------------------------------------------------------
; Constants and Global
;------------------------------------------------------

Global MseX, MseY, LastX, LastY, MoveX#, MoveY# ;mouse

Global PSpeedX# = 0

Global MXSpeed#
Global MYSpeed#
Global MZSpeed#
Global SpeedLeft#		= 0
Global SpeedRight#	= 0
Const Accel#				= 0.002
Const Decel#				= 0.002
Const TSpeed#			= 0.052
Global Obj

;------------------------------------------------------
; Create camera and pivot elements
;------------------------------------------------------

Pivot1 = CreatePivot ()
Pivot2 = CreatePivot (Pivot1)
cam = CreateCamera (Pivot2)
CameraClsColor cam,80,110,130
PositionEntity cam, 0, 0, -7
PointEntity cam, pivot2

RotateEntity Pivot2, 10, 0, 0

;------------------------------------------------------
; Create 3D elements
;------------------------------------------------------

Light = CreateLight ()
RotateEntity Light, 30,30,0

FloorTex = LoadTexture ("Character\Stone_Floor.jpg")
ScaleTexture FloorTex, 5, 5

ground = CreatePlane ()
EntityTexture ground, FloorTex
mirror = CreateMirror (ground)

EntityColor ground, 40, 120, 100
MoveEntity ground, 0, -1.25, 0
EntityAlpha ground, 0.75

CreatePrimitives ()

;------------------------------------------------------
; Load 3D character and Animations
;------------------------------------------------------

Dude = LoadAnimMesh ("Character\luigi.b3d", Pivot1)
ScaleEntity Dude, 0.01, 0.01, 0.01
TurnEntity Dude, 0, 90, 0
MoveEntity Dude, 0, -1.25, 0

; Load Character Animations
LoadAnimSeq Dude, "Character\idle_empty.b3d"			; IDLE		- Sequence 1
LoadAnimSeq Dude, "Character\walk_empty.b3d"		; WALK	- Sequence 2

Char_Idle = 1

Char_Walk = 0

;------------------------------------------------------
; MAIN GAME LOOP
;------------------------------------------------------
While Not KeyDown (1)

; Press W to toggle Wireframe
If KeyHit (17) : w = 1 - w : WireFrame w : End If

; Press the LEFT ARROW KEY to move the character left
If KeyDown (203)
SpeedLeft = SpeedLeft + Accel
If SpeedLeft => TSpeed Then SpeedLeft = TSpeed
Else
If SpeedLeft => TSpeed Then SpeedLeft = TSpeed
SpeedLeft = SpeedLeft - speedLeft/20
If SpeedLeft < 0.01 Then SpeedLeft = 0
End If

; Press the RIGHT ARROW KEY to move the character right
If KeyDown (205)
SpeedRight = SpeedRight + Accel
If SpeedRight => TSpeed Then SpeedRight = TSpeed
Else
SpeedRight = SpeedRight - SpeedRight/20
If SpeedRight < 0.01 Then SpeedRight = 0
End If

CharX# = (SpeedRight - SpeedLeft)

; Move the character
MoveEntity Pivot1, CharX, 0, 0

If Char_Idle = 1
Animate Dude, 1, 0.46, 1, 8
End If

UpdateWorld

RenderWorld

; Text elements here

Text 10, 10, "CharX: " + Abs(CharX)
Text 10, 25, "Anim Frame: " + AnimTime (Dude)

Flip

Wend

End

;------------------------------------------------------
; FUNCTIONS
;------------------------------------------------------

Function CreatePrimitives ()

For i = 1 To 100
Obj = Rand(1,4)
Select Obj
Case 1
	Obj = CreateCone (12)
Case 2
	Obj = CreateSphere (12)
Default 
	Obj = CreateCube ()
End Select

EntityColor Obj, Rand(100,200), Rand(100,200), Rand(150,250)
ScaleR# = Rand(1,2)
ScaleEntity Obj, 1, ScaleR, 1

PositionEntity Obj, Rand(-20,120), ScaleR#/2 , Rand(1.5,60)

Next

End Function


Here's a link to the character files used:
Animate_Character.zip

Any help here would be most appreciated! :-)

global Char_anim1
global Char_anim2

Char_anim1 = LoadAnimSeq Dude, "Character\idle_empty.b3d"

Char_anim2 = LoadAnimSeq Dude, "Character\walk_empty.b3d"


Animate Dude, Char_anim1 , 0.46, 1, 8


A quick look tells me tweaking these lines should work better.

Umm that doesn't work at all, your syntax is a little.... wrong ;-)

I have looked at many examples and searched the forums regarding character animation and i'm still not quite getting the logic behind animating .B3D characters.

I mean I don't get why the animate command cannot be used properly by itself in the main program loop. Everytime I try to use it by itself my animation freezes...

Animate Dude, 1, 0.46, Char_anim1 , 8


Either way - you're telling it animate an animsequence called ' 1'...you have to assign the sequence to a variable otherwise it means nothing...especially in a fully coded game.


Char_anim1 = LoadAnimSeq Dude, "Character\idle_empty.b3d"

..Also why are your anims all separate b3ds? How did you do your animations? It's tidier to do one long animated stream and load in one fully animated B3D file and then use 'extractanimseq' to chop out the anims and assign them to (global) variables.

..and another thing if 'char_idle= 1' then you have to set it to another value when you start the animation. you just have a loop going on here and the animation is constantly restarting at frame 1.

If Char_Idle = 1
Animate Dude, 1, 0.46, Char_anim1 , 8
Char_Idle = 0
End If