playMaker

Author Topic: How to Animate a char.  (Read 8169 times)

Amy

  • Playmaker Newbie
  • *
  • Posts: 36
How to Animate a char.
« on: June 01, 2012, 05:00:46 PM »
So I bought a char that comes with a whole bunch of animations. I understand some playmaker basics so my char is 'working' as in it has a char controller and a move variable set up. I'm actually walking but I'd like my char to walk when I press forward and idle when they don't. To jump on space bar, etc. I have a whole bunch of these animations just looking to get programmed....help?

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: How to Animate a char.
« Reply #1 on: June 01, 2012, 07:04:14 PM »
Basically your going to want to have a different state with a "play animation" action on it for each movement state the character will be in.

And then a "get key down" action or whatever you want to trigger to switch between those different states.

here's a simple example

State 1
Play animation action (idle animation)
get key down (gotoWalk event) (space bar)

state 2
play animation action (walk animation)
get key up (gotoIdle event) (space bar)

so when you start, it will play the characters idle animation, and when you press and hold the space bar, the character starts playing his walk animation and when you release the space bar, it goes back to the first state where he is idle again.

every other animation is expanded on that concept.
You just need to decide under which circumstances cause you to switch states.... a button press, or a axis input magnitude etc.

if you are using a "get axis vector" action for example, and store the "magnitude" into a variable, then you can use a "float compare" action and compare it to 0 to determine if the player is pressing forwards or not on the joystick.  

If the magnitude is greater than 0 then goto the walking state, if not, stay at idle.


« Last Edit: June 01, 2012, 07:06:20 PM by justifun »

gregmax17

  • Playmaker Newbie
  • *
  • Posts: 11
Re: How to Animate a char.
« Reply #2 on: June 02, 2012, 10:50:26 AM »
Hello, first time PlayMaker here, and last night I got my character to move around with idle, walk, and run animations. I basically followed this tutorial: http://www.youtube.com/watch?v=2s-M_OVQkdk

I also tried to implement a jump animation. Which I have working as well (kind of), but how do I get my character to physically jump? I have two states right now: move and jump. In the jump state, I have the "controller simple move" action which I set the move vector to a vector of 0, 8, 0 (x, y, z). But it doesn't seem to make my character jump.

Also, I have two animations in my jump: a start and land. Is there a way to detect when the character is at the apex of the jump so I can start playing the land animation?

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: How to Animate a char.
« Reply #3 on: June 02, 2012, 09:55:02 PM »
Hi Gregmax17

Jumping is a tad more tricky, cause there's a few different ways to handle it.  I'll explain the easiest way.

In order to make your capsule physically jump you'll need to remove that controller simple move from your jump state. That action should only be on the move state. 

The trick is that you will need to add a "platform input controller" or a "3rd person platform" controller to your capsule.  These are both part of unity's "Standard assets" package that you'll need to import into your scene.

You can find them in the component menu ->Character

Once you add those, you'll probably also have a "character motor" component on your character as well.  This is where you can set his run speed/jump height etc etc.

You can further tweak those variables in game later with the "character motor" action within playmaker too.

Now when you press the jump button (as setup in the unity input manager settings) your capsule will jump into the air.

One way you can determine when you character is jumping up or falling down is to have add a new fsm to your character (you can stack multiple FSMs on one object).

So right click in the FSM editor window with your player capsule selected and press "add fsm to game object"

Now you have a new fresh one on top of the existing one you have for your movement.

Here in its start state you are going to create a "get button down" action and check to see when the player presses the jump button.

When they do, you will have it switch to a new state that will play the characters "jump up" animation using the "play animation" action.

In that state as well, you will need to check which direction the player's position currently in compared to the previous frame.  This will determine if he's travelling up or down.

Create a variable called "currentPosition" of a "float" type.

Add a float compare action and have it compare "CurrentPostion" to "CurrentPosition" and check the box that says "every frame"

now add a "get position" action and set the Y value to the "Currentposition" variable.
Make sure you check the box labelled "Every Frame" because we want play maker to check all the time and store that value (the characters vertical position)

In the float compare action change the event in "If Less Than" to switch to a new state that would then have a "play animation" action that would play that "jump_falling" animation.

So to recap.  After the player presses the jump button...playmaker plays the Jump up animation.  Every frame it will check if the players previous position is higher than it was the previous frame, but as soon as it starts to be less (eg: player is falling back down), then it switches to an animation state of the falling animation.

Then to finish it off, you can use a "is grounded" state in the same state as the "play falling animation" state.  Once "is grounded" is true (when the capsule hits the ground again) you can transition back to your very first state again, where you wait for the player to press the jump button again.

Hopefully that makes sense :)