Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Coordinating Transform.position with Animation of 2D sprites

Discussion in 'Animation' started by templewulf, Aug 20, 2019.

  1. templewulf

    templewulf

    Joined:
    Dec 29, 2013
    Posts:
    52
    Hi all,

    I'm making a sprite-based 2D game that is very animation intensive. Animations can alter game properties (e.g. make character immune to projectile damage from 0.3s to 0.8s in the move), alter trigger colliders (e.g. where on the body a hitbox can make contact), and alter transform.position.

    The first two are easy enough with animated properties as in https://docs.unity3d.com/Manual/animeditor-UsingAnimationEditor.html

    The last one has been less obvious. It seems like a case for root motion, but I can't find any documentation for using it with sprites. Some solutions I've seen involve adding an empty parent to the object, but that snaps them back to local 0,0 at the end of the animation.

    For an example, look at Fei Long's Rekka Ken animation from Super Street Fighter 2 that I've attached to the post. Sub-sprites 2, 4, and 7 are when he advances forward with a punch. If I change his position via script and store that data in a ScriptableObject, that means somebody needs to remember to adjust that every time an animator changes sprite keyframe timings. This also means that I have to duplicate the work of features like easing curves in a separate script.

    Can anyone suggest any solutions that will:
    1. Animate relative to the current position. This rules out animated properties the way I've been doing, as that puts them at absolute positions.
    2. Maintain the ending position after the animation finishes. This rules out the empty parent solution.
    3. Synchronize these transform.position changes with the animation. Ideally, this means changes to position are stored in the animation itself, so we don't have to audit other data files.
    Thanks!
     

    Attached Files:

    Last edited: Aug 20, 2019
  2. templewulf

    templewulf

    Joined:
    Dec 29, 2013
    Posts:
    52
    Apparently, Root Motion works for my sprites, but I had to restart my PC several times, then uncheck and recheck "Apply Root Motion" several times on the sprite's Animator component. No idea why!

    This is Unity 2018.3.14f1, Windows 10.