x


Switching between animations

Hi, I'm terribly stumped.... I'm trying to make simple actions for my character walk, run, idle, jump... I've imported my rigged and animated character from blender. It has a controller so when I hit play, it moves correctly.. My trouble now is that I can't get the animations to match up with the correct keys.. exp, when I hit the space bar the player moves up but doesn't perform the jump animation. When i do play and hit the arrow key it plays through all the animations I made, instead of playing the right ones that correspond to the key i hit, like jump.... I've done all the frame stuff, none of the tutorials I've tried work, Idk what to do

thx

more ▼

asked Jul 03 '11 at 08:19 PM

jballew7 gravatar image

jballew7
1 4 4 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Start here:

http://unity3d.com/support/documentation/Manual/Character-Animation.html

If you still don't know what to do, come back and ask a specific question about the problem you're having- because based on the question you've asked it looks more like you dove into it without reading how to do it first :)

more ▼

answered Jul 03 '11 at 09:44 PM

testure gravatar image

testure
4.2k 20 25 48

I followed that tutorial and it worked well, but I still don't understand... In a nutshell all I'm wanting to do is make the character do the right animations at the right time. So suppose hes standing still and I press the up arrow key.. he walks forward, or If i press the space bar he jumps.. I don't understand how to make the character perform the right animation for each key pressed

Jul 04 '11 at 11:10 PM jballew7

There are examples of how to do that on the page I linked!

In fact, there is an example that is almost EXACTLY what you're asking for on that page.

function Update ()
{
   if (Input.GetAxis("Vertical") > 0.2)
       animation.CrossFade ("walk");
   else
      animation.CrossFade ("idle");

    // Shoot
   if (Input.GetButtonDown ("Fire1"))
      animation.CrossFade("shoot");

} 

So, look at that example and take a wild guess at how you would make a JUMP animation..

Jul 04 '11 at 11:32 PM testure

Ok so Ive got it going for the most part, but I've still got a couple of problems... sry Im new to Unity and scripting plz be patient, thx for you help

one is that it performs the walking animation when pressing up/down arrow keys but not when pressing one of the left/right keys just slides across the plane, also I can only get it perform the jump animation if I set it to "Fire1" but I want to be able to use the space bar, cause that is what the controller is using to make it jump.. it says that Input Button space is not setup,

this is the script Im using I just edited it to try and fit

function Start () { // Set all animations to loop animation.wrapMode = WrapMode.Loop; // except jump animation["jump"].wrapMode = WrapMode.Once;

// Put idle and walk into lower layers (The default layer is always 0) // This will do two things // - Since jump and idle/walk are in different layers they will not affect // each other's playback when calling CrossFade. // - Since jump is in a higher layer, the animation will replace idle/walk // animations when faded in. animation["jump"].layer = 1;

// Stop animations that are already playing //(In case user forgot to disable play automatically) animation.Stop(); }

function Update () { // Based on the key that is pressed, // play the walk animation or the idle animation if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) animation.CrossFade("walk"); else animation.CrossFade("idle");

// jump if (Input.GetButtonDown ("space")) animation.CrossFade("jump"); }

Jul 05 '11 at 12:47 AM jballew7

Look, we can keep going back and forth like this forever- but at the end of the day you lack sufficient knowledge to do what you're trying to do, despite having the resources right under your nose. It's not your fault, you're just trying to start in the middle rather than learn the basics and work your way up.

You need to start from zero and learn the basics before jumping into whatever it is you're trying to do. Otherwise you're going to be posting a question here every time you run into something you dont understand (which will be very frequent).

Here's my suggestion- download the Unity 3D Platformer tutorial and do it. Make sure you read and understand every word before turning the page. Don't just copy and paste the code, then move on to the next step- that's not how you learn. It's a really good tutorial and you will learn a ton from it if you take the time to understand the things it's trying to teach you.

http://unity3d.com/support/resources/tutorials/3d-platform-game.html

Sorry if this came off as harsh- but it's reality. And if you take my advice, you will gain the knowledge you need to understand how to work with unity.

Jul 05 '11 at 02:36 AM testure

Also- I'm not trying to bring you down or anything, just trying to explain that you're going about things the hard way. If you want to gain a better understanding, try the tutorial again, and anything you don't understand, post a question about it- people will be more than happy to explain whatever is tripping you up, trust me!

Just make sure you understand everything before moving on- that's important. Everything you learn builds off of something else- so if you skip something or just glaze over it, you're in for some trouble in the future.

good luck!

Jul 05 '11 at 04:39 AM testure
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3772
x1040
x335
x57
x32

asked: Jul 03 '11 at 08:19 PM

Seen: 2513 times

Last Updated: Jul 05 '11 at 04:39 AM