Jump to content

Having issues with animation end hook


Monte
 Share

Recommended Posts

Hi All,

 

It's my first time here, I have been playing around with LW for a while and just started to tinker with scripting,

I have been modifying the monster ai script but have run into problems with the animation end hook call and need help to work out where I have gone wrong

 

So when I use,

self.baseAnimMgr:SetAnimationSequence(4, 0.03, 200)

 

The animation plays fine but loops which is not what I want, so I'm trying to add the end hook using this,

 

self.baseAnimMgr:SetAnimationSequence(4, 0.03, 200, 1,self,self.EndAttack)

function Script:EndAttack()
if self.state=="attack" then

self.state="idle"

end
end

 

I have already defined the "attack" state in triggering the animation, but, the end hook seems to trigger immediately so only a few frames of the anim plays and resets.

 

Any Help much appreciated

Link to comment
Share on other sites

Looks right to me. All I can suggest is playing with the animation speed (0.03) or using the new animation commands, PlayAnimation and StopAnimation.

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

Thanks SGB,

 

I tried to use PlayAnimation and kept getting nil value errors so reverted back, I'm beginning to wonder if it is the part of the script these are placed that is the problem,

I currently have call in

function Script:UpdateWorld()

and this

function Script:EndAttack()
if self.state=="attack" then

  self.state="idle"

 end
  end

at the end of the script...

Link to comment
Share on other sites

It may be stuck in attack mode calling the animation constantly. One-shot animations should only be called once. Adding System:Print("end animation") in your EndAttack function will show in the output window if it's getting called. You can try this script on the crawler prefab and see if it helps in any way.

 

Script.mode = "idle"

function Script:UpdateWorld()
   if window:MouseHit(2) then --play crawler attack animation
       self.mode = "attack"
   end

   if self.mode == "attack" then
       self.mode = "Waiting for animation to stop"
       self.entity:StopAnimation()
       self.entity:PlayAnimation("Attack2",0.009,10,1,"EndHit")
   elseif self.mode == "idle" then
       self.entity:PlayAnimation("Idle",0.02)
   end
end

function Script:EndHit()
   self.mode = "idle"
end

function Script:PostRender()
   context:SetBlendMode(Blend.Alpha)
   context:SetColor(1,1,1,1)
   context:DrawText("Mode: "..self.mode, 400, 200)
   context:SetBlendMode(Blend.Solid)
end

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

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...