Search Unity

Animated character jumps with physics (Root Motion + Rigidbody)

Discussion in 'Animation' started by dom_cobb_22, May 4, 2019.

  1. dom_cobb_22

    dom_cobb_22

    Joined:
    Feb 6, 2014
    Posts:
    24
    Hello.
    Now I am creating Character systems: Movement, Jumping.

    So now it can move around and I use Animator and Root Motion for this. Just playing Animation Clips depending on several variables receiving from the Input.

    Next, I want to create Jump mechanic, but I don't want to use Root Motion here because I want to control the character in the air. Slightly moving him before his landing.

    So I have 4 animation clips - prepare-to-jump, jump-push, jump-fly, jump-land. I was going use this in parallel to some physics, that will push my character in the air with some force.

    I have added a RigidBody to object and AddForce in the script. But this makes conflict and work very bad. After long tunes, the best point that I can get is momentarily moving in position, where the character is should be after this Force.

    Also, Gravity does not work properly.

    My question is: How to use Animator and Physics together?
    I want to start Jump-Push animation, then add a force to the character to get him in the air, then transit to Jump-Fly animation, so like its flying, then see the gravity in action, and start Jump-Land, then the character will be in front of the ground.
     
    Last edited: May 5, 2019
  2. dom_cobb_22

    dom_cobb_22

    Joined:
    Feb 6, 2014
    Posts:
    24
    Now I found something in Model Import Settings in Animation Tab.
    It is Root Transform Position Y and XZ. I check Bake into Pose and now physics affect my character then he is in this states in Animator (in fact - the ability to turn Root Motion off on certain animation clips).

    But now I can jump only in Y-axis. Although, i wrote this code:

    private Rigidbody rb;
    public Vector3 jumpVector;
    public float jumpSpeed;

    if jump
    rb.velocity = jumpVector * jumpSpeed;


    and assign (0, 1, 3) to jumpVector in Editor.

    If I attach this to the cube (without animator), its good to jump along z-axis too.
    Character doesn't jump along the z-axis.

    BTW: Although rb.velocity do something...
    rb.AddForce(jumpVector * jumpSpeed);

    do nothing in this case.

    UPDATE: Excuse me. I forget ForceMode.
    rb.AddForce(jumpVector * jumpSpeed, ForceMode.Impulse);

    This code is driven object along Z-axis. But very strange.
    All of this happens very strange :D

    Why it dosn't translate smooth on z-axis? / / / -- -- -- \ \ \

     
    Last edited: May 5, 2019
  3. dom_cobb_22

    dom_cobb_22

    Joined:
    Feb 6, 2014
    Posts:
    24
    I turn 'Apply Root Motion' off... and its all the way good. Character pushing from the ground... make a half-circle path in the air and land on the ground.
    So, what you want to say... If I have at least one Root Motion Animation in my Character, so its all? I can't get any physics on my character properly? :eek:
     
  4. dom_cobb_22

    dom_cobb_22

    Joined:
    Feb 6, 2014
    Posts:
    24
    animator.applyRootMotion = false;
    rb.AddForce(jumpVector * jumpSpeed, ForceMode.Impulse);
    // landing
    animator.applyRootMotion = true; // !!!!!! :D


    I am speaking with myself.
    It is always good to speak with smart person :D
     
  5. jpeg_

    jpeg_

    Joined:
    Sep 5, 2017
    Posts:
    4
    thanks a lot!