Jump to content

Animation manager problem


YouGroove
 Share

Recommended Posts

When i use the following code, the "attack" animation just not terminate, it plays only the beginning ?

Any idea ?

 

 

self.animationmanager:SetAnimationSequence("attack",0.02,10000,1,self,self.EndAttack)

 

I tried many values for blending , it is better with bigger values , still it never plays the animation entirely.

Stop toying and make games

Link to comment
Share on other sites

I have a test project just for this animation project.

-Dezip all files and put all in "Models" project folder

-Open map level file "animationDebug.map" and launch the game

 

 

The goal is to have the attack animation playing entirely and the other animation playing when the state is not "attacking".

exportdebug.zip

Stop toying and make games

Link to comment
Share on other sites

This sounds like your logic is reverting the animation back to something else before your animation is finished playing. This gets into states of your game type of logic.

 

Or put a System:Print() inside your end animation function to see if that's getting called too quickly. I thought you needed to put the end frame number in SetAnimationSequence() but I could be wrong on that. Something to check out. Look at the function to see what it's parameters are.

Link to comment
Share on other sites

The code is too simple , but perhaps i don't see something ?

 

function Script:UpdateWorld()

 self.delay =Time:GetCurrent()- self.attackDelayTimer

   if self.enabled == true   then

 --timer
 if   Time:GetCurrent()- self.attackDelayTimer > self.attackDelay then

  self.canAttack = true
  self.attackDelayTimer = Time:GetCurrent()
 end





   if self.canAttack == true and  self.state == "idle"  then

  self.state = "attack" 

   end


 self:animations()

 self.canAttack = false

   end

end


function Script:animations()

if self.state == "attack"  then 
 self.animationmanager:SetAnimationSequence("attack",0.02,2000,1,self,self.EndAttack)
 --self.animationmanager:SetAnimationSequence("attack",0.02)

end

if self.state == "idle"  then  
 --self.animationmanager:SetAnimationSequence("walk",0.03,50,0,self,self.EndIdle)
 self.animationmanager:SetAnimationSequence("walk",0.03,50,0,self,self.EndIdle)
end


end

function Script:EndIdle() 

end

function Script:EndAttack() 


 self.state = "idle"  

end

Stop toying and make games

Link to comment
Share on other sites

function AnimationManager:SetAnimationSequence(sequence, speed, blendtime, mode, specialFrames, specialFrameHook, endHookScript, endHook, endFrame)

 

 

Add 1 more parameter which is the last frame count value.

 

 

Ideally the AnimationManager script would not require that parameter and use this function to get it automatically instead but it doesn't at this time:

 

http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitygetanimationlength-r70

Link to comment
Share on other sites

Instead of calling a sub function i kept animations call in UpdateWorld() and it works great now.

 

function Script:UpdateWorld()


...
...
...
if self.canAttack == true and self.state == "idle" then
self.state = "attack"
self.animationmanager:SetAnimationSequence("attack",0.02,200,1,self,self.stopAttack,30)
end


if self.state == "idle" then
self.animationmanager:SetAnimationSequence("idle",0.02)
end

...
...

end

 

I spend the day try to figure out something that should work , but doesn't work in Lua, i like less and less Lua.

It is really too permissive allowing many errors and can go weird and not work sometimes.

 

 

Bring on BlitzMax laugh.png

Stop toying and make games

Link to comment
Share on other sites

In my code all my calls to SetAnimationSequence the endHook argument does not contain "self." For example your code is

self.animationmanager:SetAnimationSequence("attack",0.02,200,1,self,self.stopAttack,30)

and mine would be

self.animationmanager:SetAnimationSequence("attack",0.02,200,1,self,stopAttack,30)

Have you tried this?

Link to comment
Share on other sites

I just tried your syntax

 

if self.state == "idle" then   
  self.animationmanager:SetAnimationSequence(self.state,0.02,200)
 end

 if self.state == "walk" then   
	 self.animationmanager:SetAnimationSequence(self.state,0.05,200)
 end

 if self.state == "attack1" then

	  if self.attackType == 1 then 
	   self.animationmanager:SetAnimationSequence("attack1",0.05,200,1,self,attack1Done)
	  else  
	   self.animationmanager:SetAnimationSequence("attack2",0.05,200,1,self,attack1Done)
	  end
 end   

 

 

It doesn't work good and worst than keeping "self." . Keeping all anims calls in UpdateWorld all just works good.

 

I posted some example , you can play with it.

Stop toying and make games

Link to comment
Share on other sites

When you pass functions around you can't pass it like that. You are basically passing function "pointers" which requires the object 'self' then the function self.EndAttack. The alternative method for calling table functions in lua is:

 

obj.func(obj) == obj:func()

 

This is why when you are in a table function you can use 'self' to refer to the table itself. Behind the scenes Lua passes the obj as the first parameter and names that first parameter 'self' when you call it with :

 

: is only syntax sugar for calling functions not passing them around.

 

This will give you an error:

Person = {}

Person.PrintName = function() print("Rick") end

test = Person:PrintName

test()

 

 

 

This won't

Person = {}

Person.PrintName = function() print("Rick") end

test = Person.PrintName

test()

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...