Search Unity

Mecanim - additive 2D position by animation curve

Discussion in '2D' started by plokkum, Nov 22, 2013.

  1. plokkum

    plokkum

    Joined:
    May 28, 2013
    Posts:
    90
    I have a cow that has a couple of random animations. For instance one where he turns and one where he walks.

    The animation where he walks, he increases its X position. Now the cow walks in a funny, stuttery way like I intended, so there is no way I could translate its X position through a script.

    What I want to accomplish is to have the cow play its walk animation and when the animation is done, keep it's X position. If the walk animation will be triggered again, it should increase its X position again relative to the X position where the last walk animation ended.

    I can use a event trigger in the animation curve to update its position when the last frame of the walk animation is reached, but I was hoping there would be a setting that would let the poor little cow keep its animated X position, so basically play the animation in sort of an additive mode.

    I hope I am explaining myself well enough and hope someone's got an answer. Thanks in advance!
     
  2. Durayel

    Durayel

    Joined:
    Aug 30, 2013
    Posts:
    5
    Make the cow a child of an empty game object, then add an event to the end of your walk animation that calls a method on a script on your cow object. In this method, set the parent game object's X position to that of the cow ie. transform.parent.position = transform.position;
     
  3. plokkum

    plokkum

    Joined:
    May 28, 2013
    Posts:
    90
    I actually tried that too, however when switching from one animation to another, the transition adds a 1 or 2 frame transition overlap even though I set it to 0%. So when I set an animation event to update the current x position while switching to, for instance, an idle animation, I will see the cow offset it's position twice as far for 1 or two frames.