1
\$\begingroup\$

I am using Unity3D 4.1 for one of my projects. I have a robot character which is always running. I am using mecanim animation system.

  • What I really want:When I press Space bar, the character should jump up in the air, triggering an animation clip and then by the time it reaches the ground, the animation clip should also end.

  • What actually is happening:When I press Space bar, the character jumps in the air. Animation clip plays as it should, but ends way before it reaches the ground. So, it looks like he is running in the mid air.

  • What have I done: I have this humanoid robot setup with a jump animation bounded with the space bar key. Also, instead of using root motion, I am directly moving the robot from code.

        //Jumping
    if(Input.GetKeyDown(KeyCode.Space)){
        rigidbody.AddForce(Vector3.up*jumpVelocty);
        anim.SetBool("Jump",true);
    
    }
    else
        anim.SetBool("Jump",false);
    

Character's Details:

  1. Rigidbody = Mass:30, Freeze rotaion:x,y,z
  2. Capsule Collider = Material: metal, center(0,4.5,0), radius:1, height:11
  3. Script = jumpVelocity:20000

Jump Animation Clip: ~ 2 seconds. I am really out of ideas how to synchronize everything. Should I make the character jump in some other way so that it quickly comes down and touches the ground to match the animation clip? If yes, please provide a direction.

\$\endgroup\$
3
  • \$\begingroup\$ I think the right way to go is using animator target matching: docs.unity3d.com/Documentation/Manual/TargetMatching.html . Unfortunately I've never tried it, and I have several doubts too on that. I hope someone could explain it clearly. \$\endgroup\$
    – Heisenbug
    Oct 19, 2013 at 9:14
  • \$\begingroup\$ @Heisenbug, the match targeting thing did not work for me at all. I have no clue how to set my animations true or false and I've tried every possible way but still the same result. Anyways, thanks a lot for showing me at-least a path. It does look like target matching is the solution. If I find anything further, I will surely update it for other's sake. \$\endgroup\$ Oct 19, 2013 at 9:44
  • \$\begingroup\$ in the mecanim video tutorial there is a working example with a jump clip landing with feet to the ground. Despite the example is working, I didn't understand exactly when and how many times match target function have to be called. \$\endgroup\$
    – Heisenbug
    Oct 19, 2013 at 9:57

1 Answer 1

2
\$\begingroup\$

You need to use multiple clips for this. Because you're using a single clip, and your jump is handled via physics, you can't really (easily) figure out the time the animation should take to complete, and even if you went that route, you'd have to slow your animation down to match.

What you need to do is split the animation into 3 separate clips, a jump, an in-air loop, and a landing animation.

You'd play the jump animation when you hit the jump button.

Transition into your in-air loop and remain there as long as the character is not grounded,

then when the character becomes grounded, transition to your landing animation.

\$\endgroup\$
5
  • \$\begingroup\$ For starters, he isn't using root motion, which would make this work correctly for a simple jump where the start and end height are the same. Even if he were, though, this wouldn't solve the issue of an uneven jump. If you watch the tutorial, they cover this around minute 33:00, and, yes, they use 3 separate clips to achieve it. \$\endgroup\$
    – raybarrera
    Oct 20, 2013 at 10:54
  • \$\begingroup\$ sorry.. I was wrong..I didn't remember the 3 clips part of the tutorial. +1 btw \$\endgroup\$
    – Heisenbug
    Oct 20, 2013 at 11:07
  • \$\begingroup\$ I can't blame you. That video couldn't be more dry. \$\endgroup\$
    – raybarrera
    Oct 20, 2013 at 11:08
  • \$\begingroup\$ exactly. Unity should provide more detailed tutorials for mecanim. Digital Tutors did a great job explaining some aspects of mecanim but then again, that was all about starting it up. \$\endgroup\$ Oct 20, 2013 at 20:13
  • \$\begingroup\$ @raybarrera thnkx a lott.. that solved my problem. :) \$\endgroup\$ Oct 20, 2013 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .