I need some help with changing between b3d anims

Blitz3D Forums/Blitz3D Programming/I need some help with changing between b3d anims

Newbie31(Posted 2012) [#1]
Hello,

I am new to the website and programming in general. I trying to make my first 3d game and I have run into problems in changing between animations with b3d file.

What I'm doing is - I load an animesh, then create a for loop to go through and animate the child nodes and extract the ani sequences then I made a varible that changes when enter is pressed then I link the variable to the animseq but when the varible changes the animseq doesn't.

Could anyone tell me what I'm doing wrong?

Here is a link to my file(megashares has been most reliable for me).
http://d01.megashares.com/dl/aoq5TJR/Stickman test.rar

[bbcode]



;Set Graphics And Global Constraints

;Set Graphics buffer
Graphics3D 800,600,2,2
SetBuffer BackBuffer()

;Set collision type values
PLYER=1
SCENE=2

;Global Constraints
Global h_value=50


Global FreeLookXS#, FreeLookZS#, FreeLookRotXS#, FreeLookRotYS#,Pitch#
Global gfxcrosshair

;IMPORTANT CREATE TYPES TO FIND SUB-ANIMATIONS FROM ROOT NODES
Global Model
Type subanim
Field model_child
Field anim
End Type

Global aniseq%=1

;------------------------------------------------------------------------------------

;Create Cameras
;Create Camera 1
Global camera01=CreateCamera()
CameraRange camera01,1,200
Global camera02=CreateCamera()
CameraRange camera02,1,200

;------------------------------------------------------------------------------------

;Create Lights
;Create Light
Light=CreateLight()
RotateEntity light,0,0,0

;------------------------------------------------------------------------------------

;Create Objects
;Create Plane
plane=CreatePlane()
EntityRadius plane,1
EntityType plane,SCENE
PositionEntity plane,0,0,0

;Create Cube
cube1=CreateCube()
EntityRadius cube1,1
EntityType cube1,SCENE
PositionEntity cube1,-10,1,5

;Create Cube
cube2=CreateCube()
EntityRadius cube2,1
EntityType cube2,SCENE
PositionEntity cube2,10,10,5


;------------------------------------------------------------------------------------

;Load Mesh
mesh=LoadAnimMesh("meshes\stickman.b3d")
PositionEntity mesh,0,0,10
ScaleEntity mesh,.05,.05,.05
RotateEntity mesh,0,180,0


;------------------------------------------------------------------------------------

;Create Player
player=CreateCube()
EntityRadius player,1
EntityType player,PLYER
PositionEntity player,0,1,0

;------------------------------------------------------------------------------------

;Create pivots
piv01=CreatePivot(player)
PositionEntity piv01,0,4,0

piv02=CreatePivot(player)
PositionEntity piv02,5,4,0
RotateEntity piv02,0,90,0


;------------------------------------------------------------------------------------

;Load Textures And Images
;Images
gfxcrosshair=LoadImage("Textures\Crosshair.bmp")

;Textures
;1 TERRAIN
terr=LoadTexture("Textures\GRASS2.jpg")
;2 CRATE
crate=LoadTexture("Textures\wcrate.jpg")
pivtex=LoadTexture("Textures\wcrate2.jpg")
;3 PLAYER TEXTURE
player_tex=LoadTexture("Textures\box.jpg")
stick_tex=LoadTexture("Textures\char_tex.jpg")

;------------------------------------------------------------------------------------

;Apply Textures To Entities
EntityTexture plane,terr
EntityTexture cube1,crate
EntityTexture cube2,crate
EntityTexture player,player_tex
EntityTexture mesh,stick_tex

;------------------------------------------------------------------------------------

;Set collision method and response values
method=2
response=2

;------------------------------------------------------------------------------------
;Collect and animate root nodes

;mesh Model
For x = 1 To CountChildren(mesh)
p.subanim = New subanim
p\model_child = GetChild(mesh,x)
walk1 = ExtractAnimSeq(p\model_child,0,110) ;walking animation
idle1 = ExtractAnimSeq(p\model_child,110,190) ;idle animation
If AnimLength(p\model_child)>=0 Then
Animate p\model_child,1,1,aniseq%,0
EndIf
Next


;-------------------------------------------------------------------------------------


;Set Key Functions
While Not KeyDown( 1 )


If KeyHit( 28 )=1
If aniseq%=2
aniseq%=1
Else aniseq%=1
aniseq%=2
EndIf
End If

;************************** Animation Sequence Notes *****************************

;do not uncomment
;mesh
; AnimSequence 0 = frames 0 to 200 [default sequence]
; AnimSequence 1 = frames 0 to 110 [walk1 sequence]
; AnimSequence 2 = frames 110 to 200 [idle1 sequence]

;************************** End Of Notes *****************************

; If KeyDown(28) ; works with "If KeyDown(28)" but not with "If KeyHit(28)"
;
; If AnimSeq(GetChild(mesh,1))=1 Animate GetChild(mesh,1),1,1,2,0
; Else
;
; If AnimSeq(GetChild(mesh,1))=2 Animate GetChild(mesh,1),1,1,1,0
; EndIf


;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;Case Select Camera
If KeyHit( 46 )

whichcamera% = 1-whichcamera%
; FreeEntity act_cam

Select whichcamera%

Case 0
HideEntity camera01
ShowEntity camera02
Case 1
HideEntity camera02
ShowEntity camera01
End Select

End If

; Toggle wireframe enable value between true and false when spacebar is pressed
If KeyHit( 57 )=True Then enable=1-enable

; Enable/disable wireframe rendering
WireFrame enable


;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

;object movement according to mouse pointer position

FreeLook(player,piv01, .1)
CamFollow(camera01,piv01,.18,8,0,0,0)

;object movement according to mouse pointer position

FreeLook(player,piv02, .01)
CamFollow(camera02,piv02,.18,8,0,0,0)

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


;------------------------------------------------------------------------------------

;Enable Collions between type_character and type_scenery
Collisions PLYER,SCENE,method,response

;------------------------------------------------------------------------------------

UpdateWorld

RenderWorld

;------------------------------------------------------------------------------------

;Set Onscreen Display

DrawImage gfxcrosshair,MouseX()-14,MouseY()-14 ; Draw the image!
;HidePointer


Text 0,0,"Use cursor keys to move about the infinite plane"
Text 0,20,"Press [C] to toggle between Cameras"
Text 0,50,"Mesh Child - Number('stickman') : "+ FindChild(mesh,"stickman")

Text 0,70,"Number of children in Stickman Mesh : "+ CountChildren(mesh)

Text 0,110,"aniseq variable : " + aniseq%

Text 0,130,"Current Animation Sequence ; " + AnimSeq(GetChild(mesh,1))

If Animating(GetChild(mesh,1))=1
Text 0,170,"mesh is animating"
Else
Text 0,170,"mesh is not animating"
EndIf


Flip
Wend

End


;------------------------------------------------------------------------------------

;Functions


Function CamFollow(cam,ent,cspeed#,dist#,hite#,xrot#,tilt#)

TFormPoint 0,hite#,-dist#,ent,0

cx#=(TFormedX()-EntityX(cam))*cspeed#
cy#=(TFormedY()-EntityY(cam))*cspeed#
cz#=(TFormedZ()-EntityZ(cam))*cspeed#

TranslateEntity cam,cx,cy,cz

RotateEntity cam,xrot#,EntityYaw(cam),tilt#
PointEntity cam,ent
End Function

Function FreeLook(Object_Horizontal,Object_Vertical, sp# = .5)
If sp# > 0 Then
Side_Direction=((KeyDown(32) Or KeyDown(205)) - (KeyDown(30) Or KeyDown(203)))
Front_Direction=((KeyDown(17) Or KeyDown(200)) - (KeyDown(31) Or KeyDown(208)))
FreeLookXS# = (FreeLookXS# + Side_Direction * (sp#/2)) * .75
FreeLookZS# = (FreeLookZS# + Front_Direction * sp#) * .75
MoveEntity Object_Horizontal, FreeLookXS#, 0, FreeLookZS#
EndIf

FreeLookRotXS# = ((MouseXSpeed() - FreeLookRotXS#) * .2 + FreeLookRotXS#) * .45
FreeLookRotYS# = ((MouseYSpeed() - FreeLookRotYS#) * .2 + FreeLookRotYS#) * .45
If EntityPitch(Object_Vertical) + FreeLookRotYS# < -25 Pitch# = -25 ElseIf EntityPitch(Object_Vertical) + FreeLookRotYS# > 45 Pitch# = 45 Else Pitch# = EntityPitch(Object_Vertical) + FreeLookRotYS#
yaw# = -FreeLookRotXS# + EntityYaw(Object_Horizontal)
RotateEntity Object_Horizontal, 0, yaw#, 0
RotateEntity Object_Vertical, Pitch#, 0, 0
MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2
End Function

[/bbcode]