Animation of Mesh Not Looping

Blitz3D Forums/Blitz3D Beginners Area/Animation of Mesh Not Looping

Hello, I just got into blitz3d and I have a .3ds file. It loads just fine, and does the animation loop only once, even though I have it set to loop. So I'm a bit confused as to what is going on here. Here is my code:


Graphics3D 800, 600

SetBuffer BackBuffer()

camera = CreateCamera()

CameraViewport camera, 0, 0, 800, 600

light = CreateLight()

man = LoadAnimMesh("walking_man.3DS")

PositionEntity man, 0, 0, 400
RotateEntity man, 20, 0, 0

Animate man, 1, 0.1, 0, 10

While Not KeyHit(1)
		
	UpdateWorld
	RenderWorld
	
	Flip

Wend
End



Edit: Obviously this is just very basic code loading and positioning a 3D mesh and running the animation sequence in a loop. That's about all I'm trying to accomplish with this code sample.

see if changing the transition works
try setting the transition to 0
the transition is between animations like walk to run not for looping i think

Animate entity[,mode][,speed#][,sequence][,transition#]

Animate man (1 , 0.1 , 0 , 0)

Ok well I changed the code to the following and it does load the mesh and animate it in a loop:


Graphics3D 800, 600

SetBuffer BackBuffer()

camera = CreateCamera()

CameraViewport camera, 0, 0, 800, 600

light = CreateLight()

Global man = LoadAnimMesh("walking_man.3DS")
Global walking = ExtractAnimSeq(man, 0, 10)
Global speed = 1

PositionEntity man, 0, 0, 400
RotateEntity man, -45, 0, 0


Walking_Anim()


While Not KeyHit(1)
		
	UpdateWorld
	RenderWorld
	
	Flip
	
Wend
End

Function Walking_Anim()

	Animate man, 2, speed, walking

End Function



But now I'm trying to figure out how to start the animation when I press a key and to have it stop when I release the key and I'm having problems figuring that one out.

I tried adding:


If KeyDown(31)
		
	Walking_Anim()	
	
EndIf



But that didn't do anything. It won't animate at all. What I was trying to do was make it so that when you press the S key (which corresponds to the WASD movement set up) it would start animating.

If I change the code to:


If KeyDown(31) = False
		
	Walking_Anim()	
	
EndIf



Then it animates in a continous loop. But if I press the S key, it doesn't stop anything. Any ideas?

That won't work, because when your holding down the key, your telling it to animate everyframe, so it's starting from the first frame all the time.

You need a flag of some sort, or:


If keydown(31) then
   If AnimSeq(entity) <> 2 then
      Walking_Anim()
   End if
Else
   Standing_Anim() ; or whatever you want to do when not animating
End If


That should sort you out. Your checking to see if the entity is animating sequence 2 (your walking animation sequence). If it isn't, then your telling it to animate. If the key isn't being held down, your telling it to animate the standing animation (or just tell it to stop if you don't have a standing animation).

If KeyDown(31)
    sequence = 2

else
    sequence = 1
endif


select sequence
    case 1 ; IDLE
        If AnimSeq(entity) <> sequence
            Animate entity, 1, .2, sequence, 10
    case 2 ; RUN
        If AnimSeq(entity) <> sequence
            Animate entity, 1, .2, sequence, 10
    ;case 3
    ;case 4
    ;case 5
    ;AND SO ON
    ;ADD AS MANY AS YOU WANT
end select


That would be a better solution :o) That's whats good about these boards.

Well I got it to work! Thanks guys! :)

I used a combination of select case and a flag. Here is what I did:


Graphics3D 800, 600

SetBuffer BackBuffer()

camera = CreateCamera()

CameraViewport camera, 0, 0, 800, 600

light = CreateLight()

Global man = LoadAnimMesh("walking_man.3DS")
Global walking = ExtractAnimSeq(man, 0, 10)
Global idle = ExtractAnimSeq(man, 5, 5)
Global speed = 1

sequence = 0
flag = 0

PositionEntity man, 0, 0, 400
RotateEntity man, -45, 0, 0

While Not KeyHit(1)
	
	If KeyDown(31)
	
		sequence = 1
		
	Else
	
		sequence = 2
		
	EndIf
	
	Select sequence
	
		Case 1
		
		If sequence = 1 And flag = 0
															
			Walking_Anim()
			
			flag = 1
			
		EndIf
			
		Case 2
			
			If sequence = 2
							
				Idle_Anim()
			
				flag = 0
			
			EndIf
				
	End Select
	
	

	
	UpdateWorld
	RenderWorld
	
	Flip
	
Wend
End

Function Walking_Anim()
	

	
		Animate man, 2, speed, walking


End Function

Function Idle_Anim()
	

	
		Animate man, 1, speed, idle

	
End Function



This code properly displays the idle animation when the key isn't being held and properly loops the animation when the key is held down! Yay!