Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: spacerobot on March 26, 2014, 08:16:01 AM

Title: How would I play an animation when player dies? [SOLVED]
Post by: spacerobot on March 26, 2014, 08:16:01 AM
I'm having a hard time getting an animation to play when my character dies. I have an animator with a death animation inside. How would I go about playing that when health = 0? (Already have the health = 0 check done, just need to figure out animation.)

Any information is appreciated.
Title: Re: How would I play an animation when player dies?
Post by: xhidnoda on March 26, 2014, 10:23:26 AM
1. For example, make a "Listener FSM" on you health. When the health is 0 just play animation.
2. Or you can just make a global event "Play Dies Animation". So, when you health = 0 send event to another(or self) FSM contain the "Play Dies Animation" event.
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 26, 2014, 10:29:04 AM
I guess I'm looking on how to actually play the animation. I have an animator controller for my player. That has my run, jump, death animations etc. So what would my gameobject be that would play the animation? Would I use playanimation or  aniamtorplay? I've tried both and haven't had any luck.
Title: Re: How would I play an animation when player dies?
Post by: lioncirth on March 26, 2014, 10:33:54 AM
You would do play animation

You need to select the GameObject that actually has the animation component on it and then write in the name of the animation to be played...This would need to be case sensitive.
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 26, 2014, 10:38:50 AM
Thanks for getting back to me. I appreciate it.

So I cannot add the animator controller to the play animation action. Do I need to get that and store it somehow as a variable or something?
Title: Re: How would I play an animation when player dies?
Post by: lioncirth on March 26, 2014, 10:44:01 AM
Having some playmaker issues so cannot do in front of me, this is off the top of my head so I hope its right :)

What I tend to do is;

I have 2 Game Objects;

* Character (With animations component)
* Health manager

On the character FSM I would have set "Get Owner" action and set Global Variable to something like "PlayerGO"

You could then have the listener action "Listen_For_Death" - Create a global event "Player_Death_Animation"

This then leads to the next state "Player Died Animation"

Set the action Play Animation - Select the death animation you want to play. (This must be in the animations list in the component)

On the Health Manager, when you get to the action were you want to play the animation.

You do a "send event" action, set the PlayerGO global variable as the target Game Object. The FSM you want to use on that player Game Object and then the global event
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 26, 2014, 11:24:25 AM
Thanks for the info. I think I am close, but it is still not playing the animation. Is there anything inside the listen state? Or does that just hook to the play death animation state?
Title: Re: How would I play an animation when player dies?
Post by: lioncirth on March 26, 2014, 11:25:39 AM
Nothing in the listen state - it simply has the global transition, which leads to the play death animation state.
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 26, 2014, 11:45:29 AM
Hmmm. It still isn't playing the animations. Do these look right for the states for the end of the health manager and player (attached)?

Title: Re: How would I play an animation when player dies?
Post by: lioncirth on March 26, 2014, 11:50:08 AM
On your send event you have it set as FSM, where as the FSM you have the listener on is FSM2

On the get owner state, put a finished transition and then link this through to the listener

On the actual play animation, have you tried;

* Setting Game Object as the global variable player
* tried setting Game Object as owner

Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 26, 2014, 01:28:18 PM
Thanks.

I fixed the FSM2 naming and added the Finished state transition to the set global.

When I change the animation to use the global var it says there are no animations available. When I select the player object though they are all listed.

EDIT: Also I see that everything is working between the two FSM's and the state is making to the final Player died animation state on the player object.

So close! Something is still off though.
Title: Re: How would I play an animation when player dies?
Post by: lioncirth on March 26, 2014, 01:55:01 PM
Can you attach a screenshot of the players inspector?
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 26, 2014, 02:08:30 PM
Here is the player inspector.
Title: Re: How would I play an animation when player dies?
Post by: lioncirth on March 26, 2014, 02:23:00 PM
I dont have the animator, are you using legacy animations?
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 26, 2014, 02:38:25 PM
The death animation is legacy.

Could my character controller script be interfering with this since it is controlling the character and not playmaker?
Title: Re: How would I play an animation when player dies?
Post by: lioncirth on March 26, 2014, 04:56:01 PM
Have you tried it with the animator component off and just having the animation component?
Title: Re: How would I play an animation when player dies?
Post by: Moza on March 26, 2014, 09:00:44 PM
I'm also having the same problems. When I use the Animator component it just plays the default animation and when I try using the Play Animation action or Stop Animation actions they don't work. I also tried just using the animation component where i removed everything and redone the animations and just had the Animation component on the Player and again the actions didn't work and not even the default animation worked.
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 26, 2014, 10:38:28 PM
I just tried it with the animator component off and I got the same results. Any chance of posting a working example for something like this?
Title: Re: How would I play an animation when player dies?
Post by: Moza on March 26, 2014, 11:09:56 PM
Ok so I went back to square one and used the Animator again and let it play it's default animation (running) and have actually managed to get it to stop playing the animation by using the Animator Start Playback action. Yes, the Start playback not the Stop playback. Have no idea why this is working but it is.
Title: Re: How would I play an animation when player dies?
Post by: lioncirth on March 27, 2014, 04:58:05 AM
I will try and get my game up - may not be till tonight though.

Mine works a little different as I have two characters in the scene. One further away and the camera goes to it and then it dies and goes back to the playable one.

In theory it should still work the same though
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 27, 2014, 01:09:23 PM
I will try and get my game up - may not be till tonight though.

Mine works a little different as I have two characters in the scene. One further away and the camera goes to it and then it dies and goes back to the playable one.

In theory it should still work the same though

That would be very helpful!
Title: Re: How would I play an animation when player dies?
Post by: spacerobot on March 27, 2014, 08:44:36 PM
I got it working!

A little different method though than we were trying here.

I created an animation trigger in the animator called isDead.

At the end of the FSM chain on the Player object my state for "Player died animation" I set an action to set animation trigger and specified the trigger isDead.

In the animator I made a transition from Any State to Death and set the condition to the isDead trigger.

I then added an "Enable Behavior" action to the Player FSM "Player died animation" that disabled my character control script so the character doesn't continue to move while he is lying on the ground.

I'm not sure if this is most optimal way to do it but it works.

Lioncirth thanks for all your help. I appreciate it.

Title: Re: How would I play an animation when player dies? [SOLVED]
Post by: lioncirth on March 28, 2014, 02:19:12 AM
Glad you got it working! :)

Something for me to remember when I use the animator!

No problem, good luck with the game and if you need anything let me know and ill see if I can help
Title: Re: How would I play an animation when player dies? [SOLVED]
Post by: traitorjoe on July 05, 2014, 10:20:04 PM
I've been beating my head against the wall all day with this problem.

@SpaceRobot - would you mind please explaining what you mean by "I set an action to set animation trigger and specified the trigger isDead"... I don't see any PlayMaker actions like this that work.