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

How to go back to a previous state exactly as it was when it was exited?

Discussion in 'Animation' started by Emperor, Aug 21, 2019.

  1. Emperor

    Emperor

    Joined:
    Feb 13, 2014
    Posts:
    41
    I have a floating cube with root motion (necessary) applied and 2 animations. One is the idle animation and another one is the hit animation. The idle animation makes the cube go up and down. The hit animation makes the cube rotate and move back briefly before recovering. After getting hit, the animator transition to playing back the idle animation.

    The problem is that when the cube gets hit, the cube goes back to moving up and down (idle animation) from the position it was at when it got hit. The end result is that if you hit the cube each time when it is going up in its idle animation, the cube will increasingly go higher and higher because the animation restarts completely instead of resuming from where it was at in the cycle... This is of course undesirable.

    I have some idea how to solve this in code but I feel like there should be an easy way to do this without any script. Any suggestions?
     
  2. TimmyTheTerrible

    TimmyTheTerrible

    Joined:
    Feb 18, 2017
    Posts:
    186
    What you probably want to do is have the cubes idle up and down animation animated separately from the root motion of the object.

    As an example, your cube could be animated with 2 transforms, the first one being the actual root of the object, and the second one being the one that moves up and down upon being hit.

    This way, the up and down motion doesn't get applied as root motion.
     
    Emperor likes this.