Animation Probs

Blitz3D Forums/Blitz3D Beginners Area/Animation Probs

sigi(Posted 2003) [#1]
Hi,
i have an animated Raptor loaded with "LoadAnimMesh" and
added AnimSequences with "LoadAnimSeq".
First i animate the Raptor with this:
Animate raptor,1,0.4,2,1.
Now i shoot at the Raptor and countdown a raptorhealth variable(from 100).
If the Variable=0 the Raptor should play another AnimSequence. But after the Raptorhealth Variable reaches 0
the first Anim stops and if i shoot one more time (raptorhealth=-10) the next animseq is playing. Why this?

If raptorhealth=0 ;Animation Stops - if raptorhealth is -10
;the next animation plays
Animate raptor,3,0.4,3,0
;EntityAlpha raptor,0.5
;HideEntity raptor
;PlaySound(raptordie)
ChannelVolume raptorchannel,0
EndIf

Thank you


jhocking(Posted 2003) [#2]
I'd have to see the rest of your code to be sure but it looks like you are calling the Animate command every frame while raptorhealth=0. What you want is to only call Animate once to start playing the animation. In other words have your If statement check if the animation is already playing.


sigi(Posted 2003) [#3]
Ok,
Here is the whole Code without Includes, can you please
look at it? Thank you.
Include "functions.bb"
Include "constants.bb"
Include "types.bb"
Include "globals.bb"

Graphics3D 1024,768,32
SetBuffer BackBuffer()

HidePointer() ; löscht mauszeiger im windows-modus

Collisions COLLISION_PLAYER,COLLISION_OBSTICLE,2,2
Collisions COLLISION_BULLET,COLLISION_OBSTICLE,2,1
Collisions COLLISION_BULLET,COLLISION_RAPTOR,2,1
Collisions COLLISION_PLAYER,COLLISION_RAPTOR,2,2

;setup lighting
;Global light=CreateLight()
;RotateEntity light,45,45,0
;LightColor light,126,126,126
;AmbientLight 70,70,70


;himmel
Global skytexture=LoadTexture("textures/myclouds1.bmp")
ScaleTexture skytexture,4000,4000
Global skyplane1=CreatePlane()
PositionEntity skyplane1,0,400,0
EntityTexture skyplane1,skytexture
;FreeTexture skytexture - nicht freigeben, wird zur bewegung gebraucht
RotateEntity skyplane1,0,0,180
EntityFX skyplane1,8
;EntityBlend skyplane1,4
EntityType skyplane1,COLLISION_OBSTICLE
EntityPickMode skyplane1,2

;boden
plane=CreatePlane()
EntityType plane,COLLISION_OBSTICLE
EntityPickMode plane,2

Global grass_tex=LoadTexture( "textures/gras_1.bmp");terrain-1.jpg" )
EntityTexture plane,grass_tex
FreeTexture grass_tex

;player
player=CreatePivot() ; pivot fuer kamera = player
EntityRadius player,0.85 ; radius fuer kollision
PositionEntity player,0,0.85,0 ; eyes height
EntityType player,COLLISION_PLAYER

;camera
camera=CreateCamera(player) ; kamera an pivot binden
TranslateEntity camera,0,0.85,0
CameraRange camera,0.2,4000
CameraFogMode camera,1
CameraFogRange camera,1,80
CameraFogColor camera,100,110,100
CameraClsColor camera,100,100,110
ears=CreateListener(camera)

backgrsound=LoadSound("sounds/wind.wav")
LoopSound backgrsound
PlaySound backgrsound

raptorwav=Load3DSound("sounds/db_growler2.wav")
raptordie=Load3DSound("sounds/db_runtaur.wav")

gunfire=LoadSound("sounds/db_gun1.wav")
jumpsound=LoadSound("sounds/jump.wav")

fort=LoadMesh("models/fort1.3ds")
EntityType fort,COLLISION_OBSTICLE
PositionEntity fort,5,0,0
EntityPickMode fort,2

;Global raptor2=LoadMesh("models/L-Thug-Attack1.x")
;EntityType raptor2,COLLISION_RAPTOR
;PositionEntity raptor2,-10,0,0
;EntityPickMode raptor2,2

raptor=LoadAnimMesh("models/raptor_static.3ds")
LoadAnimSeq(raptor,"models/raptor_attack.3ds")
LoadAnimSeq(raptor,"models/raptor_idle.3ds")
LoadAnimSeq(raptor,"models/raptor_die.3ds")
LoadAnimSeq(raptor,"models/raptor_move.3ds")
LoadAnimSeq(raptor,"models/raptor_impact.3ds")
EntityType raptor,COLLISION_RAPTOR,True ; ohne True keine Kollision bei AnimMeshes
ScaleEntity raptor,1.1,1.1,1.1
PositionEntity raptor,20,0.1,10
EntityRadius raptor,1.5
EntityPickMode raptor,2

LoopSound raptorwav
raptorchannel=EmitSound(raptorwav,raptor)

Animate raptor,1,0.4,2,1

mp5.gun = New gun ; create a new gun (mp5)
mp5\gun_handle = LoadMesh("models/mp5.3ds",camera) ;waffe gunpivot zugeordnet
ScaleEntity mp5\gun_handle,1.2,1.2,1.2 ; scale mp5-gun
mp5\gun_x# = 0.15 ; set gun coordinates
mp5\gun_y# = -0.22
mp5\gun_z# = 0.33
PositionEntity mp5\gun_handle,mp5\gun_x#,mp5\gun_y#,mp5\gun_z#
TurnEntity mp5\gun_handle,0,4,5
mp5\gun_pivot = CreatePivot(mp5\gun_handle) ; pivot for the mp5-gun
PositionEntity mp5\gun_pivot,0,0,0.2

colt.gun = New gun ; create a new gun (colt)
colt\gun_handle = LoadMesh("models/colt.3ds") ;waffe gunpivot zugeordnet
ScaleEntity colt\gun_handle,1.8,1.8,1.8
colt\gun_x# = 10 ; set gun coordinates
colt\gun_y# = 0.5
colt\gun_z# = 10
PositionEntity colt\gun_handle,colt\gun_x#,colt\gun_y#,colt\gun_z#
TurnEntity colt\gun_handle,0,4,0

muzzle1=LoadSprite("textures/muzzleflash_front_2.jpg",2,mp5\gun_pivot)
PositionEntity muzzle1,0,0.1,0.4
ScaleSprite muzzle1,0.2,0.2
EntityAlpha muzzle1,0.0
EntityFX muzzle1,1

Global mousepointer=LoadSprite("textures/my_crosshair_2.bmp",2,camera)
PositionEntity mousepointer,0.008,-0.013,1.5;0.8
ScaleSprite mousepointer,0.02,0.02
EntityBlend mousepointer,3 ; macht crosshair besser sichtbar, auch in der Entfernung


mypanelleft=LoadImage("textures/mypanel_left.bmp")
MaskImage mypanelleft,0,0,0

sniperpanel=LoadImage("textures/sniper.tga")


While Not KeyDown( 1 )

;Framecounter_nur fuer FPS-Anzeige
Framecounter_counter=Framecounter_counter+1
If Framecounter_time=0 Then Framecounter_time=MilliSecs()
If Framecounter_time+1001 <MilliSecs() Then
Framecounter_framerate=Framecounter_counter
Framecounter_counter=0
Framecounter_time=MilliSecs()
EndIf
;End Framecounter


If KeyHit(17)= True Then enable=1 - enable ; W-Taste ist wireframe
WireFrame enable


Repeat
elapsed=MilliSecs()-time
Until elapsed

ticks=elapsed/period

tween#=Float(elapsed Mod period)/Float(period)

; --------------------------------------------------------------
; Update game and world state
; --------------------------------------------------------------

For k=1 To ticks

time=time+period
If k=ticks Then CaptureWorld
UpdateGame ()
UpdateWorld

Next

RenderWorld tween#

; 2D drawing
DrawImage mypanelleft,20,GraphicsHeight()-40

If MouseDown(2)
DrawImage sniperpanel,0,0
CameraZoom camera,3
HideEntity mousepointer
Else
CameraZoom camera,1
ShowEntity mousepointer
EndIf

;Text GraphicsWidth()/2,GraphicsHeight()/2,"+"
;Text 10,0,"y-achse: " +cy
;Text 10,20,"x-achse: " +cx
Text 10,40,"Hoehe: "+EntityY(player)
Text 10,80,"fps: "+Framecounter_framerate
Text 10,120,"raptorhealth "+raptorhealth
; end 2D drawing

Flip

Wend

End

Function UpdateGame()

rot#=rot#+0.7 ; rotate colt
RotateEntity colt\gun_handle,0,rot#,0 ; rotate colt
;MoveEntity colt\gun_handle,0,(Rnd(0,0.1)),0


skytex_x#=skytex_x# + .0002 ;wolken bewegen
PositionTexture skytexture,skytex_x#,0 ;wolken bewegen

;jumping
If jumping=0
If KeyDown(57) Then yvel#=jumpvel# ; leertaste
If KeyDown(57) =True Then PlaySound(jumpsound)
jumping=1
gravity#=0.09 ; verringert gravity, player kann hoeher springen
EndIf

If jumping=1
yvel#=yvel#-jumpgravity#
by#=by#+yvel#
EndIf

If by#<1 Then by#=1 yvel#=0 jumping=0 gravity#=0.3

;speed#=speed# * .99
TranslateEntity player,0,yvel#,speed#
;end jumping


If KeyDown( 205 )=True Then MoveEntity player,backwardspeed#,0,0 ;right arrow key
If KeyDown( 203 )=True Then MoveEntity player,-backwardspeed#,0,0 ;left arrow key
If KeyDown( 208 )=True Then MoveEntity player,0,0,-backwardspeed# ; down arrow key
If KeyDown( 200 )=True Then MoveEntity player,0,0,forwardspeed# ; up arrow key

;mit shift-taste
If KeyDown( 205 ) And KeyDown(54) = True Then MoveEntity player,backwardspeed#/2,0,0 ;right arrow key
If KeyDown( 203 ) And KeyDown(54) = True Then MoveEntity player,-backwardspeed#/2,0,0 ;left arrow key
If KeyDown( 208 ) And KeyDown(54) = True Then MoveEntity player,0,0,-backwardspeed#/2 ; down arrow key
If KeyDown( 200 ) And KeyDown(54) = True Then MoveEntity player,0,0,forwardspeed#/2 ; up arrow key

;kriechen
If KeyDown(157) = True
PositionEntity camera,0,0.2,0 ; eyes height
Else
PositionEntity camera,0,1,0
EndIf ; kriechen ende

;mouselook
cx=(cx-(MouseX()-(GraphicsWidth()/2))) Mod 360
cy=(cy+(MouseY()-(GraphicsHeight()/2))) Mod 360

If cy<-90 Then cy=-90
If cy>80 Then cy=80

RotateEntity player,cy,cx,0

MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 ; muss hier stehen, sonst unter 360 Grad

TranslateEntity player,0,-gravity#,0 ; gravity
;end mouselook

If raptorhealth=0
Animate raptor,3,0.4,3,0
;EntityAlpha raptor,0.5
;HideEntity raptor
;PlaySound(raptordie)
ChannelVolume raptorchannel,0
EndIf

If MouseHit(1)=True

target=CameraPick(camera,GraphicsWidth()/2,GraphicsHeight()/2)
mytarget=CreatePivot()
PositionEntity mytarget,PickedX(),PickedY(),PickedZ()

shootbullet()

PlaySound(gunfire)
EntityAlpha muzzle1,0.9
Else
EntityAlpha muzzle1,0.0
EndIf

updatebullets()


sigi(Posted 2003) [#4]
Any Help, please?
Thanks


jhocking(Posted 2003) [#5]
Have you checked what I mentioned above? When I said I would need to see the rest of your code to be sure I didn't mean I want to (frankly I don't have time) but that I'm not 100% sure. Still it strikes me as a pretty likely reason for your problem: instead of calling Animate just once to start playing the animation, you call it every frame raptorhealth=0 (which is every frame until it is hit again) thus resetting the animation every frame.


sigi(Posted 2003) [#6]
Thank you for your help jhocking.

I will rewrite the complete code,
because i have found another bug that makes me crazy.
Some Codepieces are grabbed from the Forum and the Archives.
But i will understand every single peace of the Code, so i
am starting new.