Search Unity

Best way to handle character animation direction change for a 2.5D game?

Discussion in 'Animation' started by victus_maestro, Jul 10, 2019.

  1. victus_maestro

    victus_maestro

    Joined:
    Apr 21, 2019
    Posts:
    15
    Hello all, this is a long question to explain but should be a pretty easy answer for some...I am working on a side scroller and I was wondering about the best way to implement the direction changes for my character. I plan on using a blend tree for the walking/running, but I want a smooth turn that incorporates a skid if doing a quick U-turn.

    I have an idea of how to achieve that, but the question is this: how and when is the best time to implement the GameObject's direction change? I know that by changing the GameObject's rotation by 180, I can reuse the symmetrical animations.

    My thought was to immediately change the direction at the beginning of the skid animation, and compensate in the animation clip to make it look correct. By registering the GameObject's direction change immediately upon the intent of changing direction, I feel like I can work independently of any later transitions between the skid and move states.

    Hopefully, I have explained this well and it makes sense what I'm trying to say. Does this sound like a good way to do it? If you'd recommend any other method, I'm open to suggestions.

    Thanks all!
     
  2. JohnPet

    JohnPet

    Joined:
    Aug 19, 2012
    Posts:
    78
    The way I would go is rotating the player. When rotation is happening (check with bool?), trigger the animation. It is generally not a really good idea to compensate on animations to do the work, as it may not feel as smooth. Hope this helped. :)
     
  3. victus_maestro

    victus_maestro

    Joined:
    Apr 21, 2019
    Posts:
    15
    Thanks for the input, JohnPet! I did consider that might be an issue, and on reflecting on it I realized that if there was any timing discrepancy between the player direction flip and the playing of the animation, there would be a very ugly hiccup in the motion that would certainly be noticeable.

    I was mostly trying to avoid dealing with synchronizing the animation turning and the GameObject turning simultaneously, but I realized that I could just temporarily set a parent in Blender to simulate the GO's rotation to make sure it reads as a natural action.

    My thought was that I would be best served to have the rotation run completely during the transition clip into the skid, would you agree?
     
  4. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    885
    I wouldn't use rootmotion, it (mostly) won't be precise and you need precise rotations for platformer
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,435
    Your initial plan is the best one, but it only works if the transition to skid is instant. If you want to blend into skid, it becomes worse.

    If your turn animation is interrupted by a damage animation (or anything else), you really want the character to be facing the correct direction.

    If the turn is instant (single-frame), you just turn the object instantly and have the skid animation be in reverse. Then if you're interrupted, you're fine, you're facing in the correct direction.

    If it's not instant (you want to blend into it a bit), you're going to have to turn the model later, as otherwise the frames you're blending from will be in reverse. That means that if you get interrupted, you have to either notice that you should be turning, and then finish turning instantly, or abort the turning.

    My advice is... have the turn happen in a single frame, do your original idea. If you need a blend, get ready for some tears.
     
  6. victus_maestro

    victus_maestro

    Joined:
    Apr 21, 2019
    Posts:
    15
    Thanks for the continued input!

    @dibdab, just so I'm sure I understand what you're suggesting, you also recommend an instant change with any visual compensation happening in the animation part of it?

    @Baste Ooh, that's a very good point. I was initially worried about managing durations of the actions and coordinating multiple rotation angles, but that does completely neglect the chaos of outside forces.

    My initial idea was an instant flip in direction and then start the skid clip with the character starting facing what would otherwise be backward. The main thing is just to make sure the two happen absolutely simultaneously, or there will be a noticeable twitch in the character.

    I feel like that would also be easier in terms of abstracting my animation controls from my character controls, which I would expect will save me misery in the inevitable troubleshooting stage.
     
    Baste likes this.
  7. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    885
    you can play simply rotate the transform by degree
    Code (CSharp):
    1. transform.Rotate(0, yAngle, 0, Space.Self);
    when you reach 45/90/180, stop
    and play the nonrootmotion animation while turning (the root in script)
     
  8. victus_maestro

    victus_maestro

    Joined:
    Apr 21, 2019
    Posts:
    15
    @dibdab I see, the only concern I have is as Baste was saying, how if the core GameObject's change isn't instant, then it needs to be carefully handled to make sure an interruption to the action doesn't derail its completion of the turn.

    I'm working on the block in for the character and rig right now, so I'll post an update as I try out some dry runs of the different methods.
     
  9. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,435
    Protip: when animating a player character with an Animator component, try HAMMERING EVERY BUTTON ON THE CONTROLLER REAL FAST LIKE.

    You'll be surprised by how much breaks when the player just goes nuts. There's nothing in your game that's as much as a chaotic outside force as the player character itself.
     
  10. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    885
    I think you can record the rootmotion of the animationclip. (float yAngle)
    if you know the duration of animation, I think you could do rotate prodecurally so it would end up on 180 while keeping the speed of rotation of the original.

    if there's a damage animation while turn, you add it via blend-tree based on where the attacker is (ahead, R/L, behind)
     
  11. JohnPet

    JohnPet

    Joined:
    Aug 19, 2012
    Posts:
    78
    I didn't really understand what you tried to do with that parent. Could you please simplify it? (sorry)

    Another thing that you could do is trick the eye: Try making the rotation instant and the animation will trick the eye that the player is turning. Let me help you visualize this with an example.

    1: Character is running to the left (player holds left input).
    2: Player snaps input to right. Character pauses movement.
    3: The character gameobject instantly snaps/rotates to the right. Right at the snapping moment, the animation transistions from Running -> Skid -> Running (But in my example, skid includes pivoting 180 degrees). Note, all these animations are non-root motion. Essentially during this step, the gameobject has rotated instantly, but the animation makes it look like it rotates smoothly to other direction.
    4: Character movement resumes, keeps running, to the right this time.

    Another thing you could do is animate a pivot animation and match the rotation speed to that of the animation (doesn't have to be exact).

    I would recommend studying uncharted and assassin's creed player movement, but break the controls. Hammer the movement keys/analogue stick, as @Baste said, and you may begin to realize the way they are pulled off. Another game to take into consideration is Arhkam City. Check how smoothly Bats pivots. I think Bats is purely code, no root motion.
     
  12. victus_maestro

    victus_maestro

    Joined:
    Apr 21, 2019
    Posts:
    15
    @Baste That's a good point, I'll have to do that.

    @dibdab That's also true, I'll have to consider root motion too. I will definitely consider giving that method a try.

    @JohnPet You've got it exactly right. That was what I was thinking would be the best method. I haven't looked into 3D animation cycles, but that would certainly give me some opportunity to dissect the blends.
     
unityunity