Search Unity

how to sync dash animation with position?

Discussion in '2D' started by MatheusCohen, Oct 19, 2020.

  1. MatheusCohen

    MatheusCohen

    Joined:
    Aug 24, 2017
    Posts:
    57
    Hi,


    any idea how to sync your character position with a dash animation where the sprite has a different position during the animation? (example below)

    I could just calculate the animation size and reposition the transform after the animation, but what happens when there is a wall closer than the total animation size? I figured I could just not allow the player to dash...but that seems to be a poor solution.

    ex:

    upload_2020-10-18_21-27-20.png
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    There's different approaches to this, but I would keep the body in the same spot by setting the pivot point on the body. When dashing, the body's transform is moved forward to create the movement. The dash effect, then, appears behind the body. This way, the collider for the body will correctly ram into a wall, stopping movement. If the player were to dash into a wall, the dash effect would appear to the left of the body, but the body itself wouldn't budge.
     
    Cornysam likes this.
  3. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,463
    Lo-renzo is right. You are going to have a much easier time with movement animations if you keep the sprite in the position of the canvas. Use physics or alter the transform to dash the player and have a separate animation for that dash effect spawn behind the character.

    Bonus tip, even doing it Lo-Rens way you can have the player be unhurtable by deactivating the player's collider for a period of time during the dash. I.E. so he doesnt get hit.
     
  4. MatheusCohen

    MatheusCohen

    Joined:
    Aug 24, 2017
    Posts:
    57
    Problem with that approach is that the animation "trail" wont match with the player stsrting point :p

    I das already aware of this solutions, i though there could be a more sofisticated way to resolve this
     
  5. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,463
    There are plenty of videos of "trails" and similar stuff like that. You should be able to do something like that:

     
  6. MatheusCohen

    MatheusCohen

    Joined:
    Aug 24, 2017
    Posts:
    57
    Its also not a trail, as it is a part of the pixel art animation...but thnx!
     
  7. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,463
    Understood, but I meant that you may have to change your approach and turn it into a trail by separating the current animation into one for the dash and then add a trail. Let me know if you find another way, im definitely interested.