Search Unity

Play specific frames from an animation.

Discussion in 'Scripting' started by MachineHead, Jul 17, 2019.

  1. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    30
    In unity2D. Character has a jump animation. From launching, falling to landing animation. I put all three into one whole animation cycle in the animator.

    I need frames 4-8 to cycle while hes in the air and as he reaches the ground he goes for his landing animation.

    What is currently happening, is that if I lock my player in place in the air, he will cycle through the whole jump animation. From launching, to falling, to landing.

    How to I go about making this work properly? That when he is in the air for an extended amount of time, play the falling animation, frames 4-8.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    I don't do a lot of animating, but I think the easiest way is going to be to employ three separate animations (you can chop 'em up on import to Unity) and three separate states in an Animator, driven by code that tells the Animator when to stop looping the in-air animation and continue to the ground animation. Maybe someone who does a lot more animating can chime in too?
     
  3. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    30
    I was thinking of chopping them up separately as well. In fact, I did try. I had separated the frames of the fall animation and had it set to play while isGrounded= false.

    Doing so, it would skip the launcher part of the animation of the jump, and go straight to the middle part of the jump. The falling part. Upon landing, it would go straight to the idle animation. Works fine for more of an 8bit game with minimal animation, but not something with more intensive Sprite work.

    I need a timer of sorts. To play the falling animation and loop it while isgrounded= false and after a period of time in the air has passed so the launcher animation can play.

    For the landing. I was thinking of a raycast below the check ground raycast. An isClose raycast, if you will. To play the landing frames for the transition to the ground.

    I've seen transition animation parts in the animator, just not sure if this is more of a coding thing than an animation thing. Because I need code to check how long they are in the air, or something of the sort.
     
    Last edited: Jul 17, 2019