- Home /
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
Answer by testure · Jul 03, 2011 at 09:44 PM
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 :)
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
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 JU$$anonymous$$P animation..
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.wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop; // except jump animation["jump"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.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 ($$anonymous$$athf.Abs(Input.GetAxis("Vertical")) > 0.1) animation.CrossFade("walk"); else animation.CrossFade("idle");
// jump if (Input.GetButtonDown ("space")) animation.CrossFade("jump"); }
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. $$anonymous$$ake 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 $$anonymous$$ch 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.
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!
Your answer
Follow this Question
Related Questions
Loop animation until character reaches hit.point 1 Answer
Animation State issue 2 Answers
Minor Addition to Jumping using CharaterController 1 Answer