Search Unity

Question How to "Jomp-Walk"?

Discussion in 'Animation' started by KasunL, Feb 2, 2023.

  1. KasunL

    KasunL

    Joined:
    Apr 19, 2015
    Posts:
    64
    Hi.

    (Sorry for the typo in the title, it's "Jump-Walk)

    I've managed to write a simple script for my character to move Forwads, backwards, sideways and, Jump. But i cannot figure out how to jump while I'm walking (i.e. to press Spacebar while holding 'W' tp do a "Walking-Jump").

    Forwards walking code:

    Code (CSharp):
    1. if (vertical > 0f) // FWD anim: vertical > 0 when user hits 'W'
    2.             {
    3.                 //if(Input.GetKeyUp(KeyCode.Space))
    4.                 //{
    5.                 //    cAnimator.SetBool("bool_WalkFWD", false);
    6.                 //    cAnimator.SetBool("bool_Jump", true);
    7.                 //}
    8.                 //else
    9.                 //{
    10.                 //    cAnimator.SetBool("bool_Jump", false);
    11.                 //}
    12.                 cAnimator.SetBool("bool_WalkFWD", true);
    13.             }
    14.             else if (vertical < 0f) // BWD anim: -vertical 'S'
    15.             {
    16.                 cAnimator.SetBool("bool_WalkBWD", true);
    17.             }
    18.             else if (vertical == 0) // vertical = 0, transition to Idle-animation either from fwd or bwd anim
    19.             {
    20.                 cAnimator.SetBool("bool_WalkFWD", false);
    21.                 cAnimator.SetBool("bool_WalkBWD", false);
    22.             }
    As seen above (commented out), I tried to catch Spacebar presses inside (vertical > 0) -- move forwards script, and inside the if-statement i set the walking animation state to false and Jumping to true. But this didn't work. This is my first attempt to create a character move setup myself, and i can't figure out how to Jump while walking. I watched a couple of tutorials but they used different animator setups (more complex) that i couldn't apply to my animator setup, and code.
    Any pointers please?
     
  2. DugganSC

    DugganSC

    Joined:
    Feb 6, 2014
    Posts:
    7
    Not an expert here, but I think we're missing some important context. Inside which event or function are you putting this code? What object is cAnimator? I'm guessing an Animator, but I don't want to assume. Have you checked your Animator diagram to ensure that changing that boolean value will transition from the current state to the desired one? Actually, could you post that Animator diagram?