YouGroove Posted October 15, 2015 Share Posted October 15, 2015 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. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted October 15, 2015 Author Share Posted October 15, 2015 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 Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted October 15, 2015 Share Posted October 15, 2015 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. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted October 15, 2015 Author Share Posted October 15, 2015 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 Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted October 15, 2015 Share Posted October 15, 2015 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 Quote Link to comment Share on other sites More sharing options...
YouGroove Posted October 15, 2015 Author Share Posted October 15, 2015 I added lats frame of animation as parameter , but it is no changes. self.animationmanager:SetAnimationSequence("attack",0.02,200,1,self,self.EndAttack,30) Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted October 15, 2015 Share Posted October 15, 2015 Put a System:Print() inside end animation and see if it's getting called too soon. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted October 15, 2015 Author Share Posted October 15, 2015 I already display the state, when it displays idle the animation plays, when it displays attack the animation is like stuck on first frame or trying to start. context:DrawText(self.state, 20, 430) I'm stuck for now Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted October 15, 2015 Author Share Posted October 15, 2015 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 Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted October 15, 2015 Share Posted October 15, 2015 This will have less to do with the language and more to do with the structure of your code. At a 5 second glance I don't know why that should matter, but I haven't dug that deep into what you have. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted October 15, 2015 Author Share Posted October 15, 2015 I posted the example, see it by yourself if you have time. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
thehankinator Posted October 16, 2015 Share Posted October 16, 2015 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? Quote Link to comment Share on other sites More sharing options...
YouGroove Posted October 16, 2015 Author Share Posted October 16, 2015 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. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Einlander Posted October 17, 2015 Share Posted October 17, 2015 Wouldn't calling a script be self:Endattack and not self.Endattack? Also if you want to ignore using callbacks altogether, just set the self.state directly after you call the animation. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 17, 2015 Share Posted October 17, 2015 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() 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.