Forum rules - please read before posting.

Moving 2D Player position in custom animations

edited September 2020 in Technical Q&A

Hello AC community,

First of all, using AC 1.71.8, and Unity 2020.1.4f1. Also the 2D Animation Package, with Unity's Sprite Library Asset / Sprite Resolvers to swap sprites (different outfits) occasionally. And using Sprites Unity Complex.

The Hierarchy structure of the Player character looks like this:

Been looking to find a way to animate the Player's position during a cutscene -- in animation clips.

I'm aware of the 2D Timeline track, which can be useful for animating the regular walk animations and the position around the screen.
Or by just using ActionLists to have the Player move to a marker.

Though the issue comes in when there are custom animations, meaning swapping the sprites to a different outfit, requires Sprite Resolvers to be defined / recorded in an animation clip.

Then to move the Player around the screen (walking, etc.) in the custom animation clip, the X or Y position is animated, though this causes issues with the Player in other scenes, which I mainly understand why from threads like this which explains AC controls the Player's root object position at all times.

Though in another thread it was mentioned to animate the root's position property when using the 2D Animation Track (my Animator is on the root). So tried animating the root anyway in a custom animation clip -- though it causes the Player to not be able to spawn correctly or move in other scenes.

Also tried animating the position properties of the GameObject under the root.
Next, tried animating the individual GameObjects with sprites (e.g. NathanWalk_L, etc).
Both of these didn't work to animate the positions properly (the Player's positions that were recorded in the clip appeared in different positions in "Play" mode).

Are there any thoughts or ideas to animate the Player's position in a custom animation clip?
For instance, the first thread linked above mentioned: reset the position back to (0,0,0), though am unclear on the details of how that would work. It also mentioned using Object: Teleport.

Am aware of the fact that an NPC could just be created with the Player's different sprites (outfit) as a "stand-in" for any needed cutscenes. Though it seems it would be ideal to have everything together and just one Player instance if possible -- at least in the prefab.

It's much appreciated for any help that is provided!


  • Animating an object's child would cause the animations to be recorded in local space - which may or may not be appropriate, as the final placement of the sprites would depend on the position of the root object.

    What's the actual context here? Are you playing something mid-way through a scene, always from the same starting place? Or is it more dynamic?

    The simplest way should be to just control the root position through Timeline. The "2D Animation Track" can be left out - that's just to play standard animations, and won't affect the character's position.

    If you tried that before, can you share more details about what exactly happened?

    One thing to keep in mind is that AC will only control a character's position if their Motion control field is set to Automatic. Try setting this to Manual instead - if need be, you can change this value through script at the start/end of the sequence.

  • edited September 2020

    Thank you!

    The cutscene has two NPCs walk into the scene. Then the Player also walks into the scene after that.

    The two NPCs were already set up to move into the scene using an ActionList and markers. Originally I had thought about using Timeline, though was just wondering if there was another way to animate the Player without it. And have all the characters including the Player could move into the scene using the ActionList, and custom animation clips.

    Using Timeline is essentially the same thing as animation clips though, and it works -- so am using that.

    The only small issue with Timeline I have to account for is that after the Timeline ends at the last keyframe, the Player animation clip (and sprites) always change back to the original skin (outfit) pose, even if the duration of the cutscene hasn't ended yet.
    It makes sense, as likely since the Controller, or AC takes control of it at that point.

    So to account for that, extending the Timeline's last keyframe longer than the cutscene's duration works.
    Or, adding a Signal on the last keyframe to run an ActionList which plays an idle animation clip with the Player's new skin (outfit) pose so he remains that way.

    Changing the "Motion control" field sounds interesting way to approach this as well. Haven't tried that yet, am as unsure of what script would be needed to change the value. Though it sounds like it would be useful for the future, if any other advice with that can be added.

    Thanks again!

  • Since you're using Sprites Unity Complex, what animation gets played - outside of Timeline - is totally dependent on the Animator parameter values.

    AC will only control the parameter values you allow it to - but the effect those values have can be overridden by another parameter that you can incorporate.

    For example, if you had a Bool parameter named "PlayCustom", you could wire up a transition in your Base layer to always play a custom animation - regardless of the state of your "Move speed float", etc.

    Upon exiting Timeline, the Animator will revert back to its original state - i.e. controlled by parameter values - but one thing you can try is to set up whatever custom parameter values you want before running the Timeline, so that your Animator is playing a custom animation when the Timeline ends.

  • edited September 2020

    So essentially a custom parameter can be run (along with the corresponding custom animation), before the Timeline starts.
    Then, that custom animation (for example an Idle state with the Player's new outfit / sprites) will still play once the Timeline ends. I did this and it worked.

    That was similar in concept to what I mentioned above about using the Signal on the last keyframe of the Timeline -- to run an ActionList which changed the parameter to play the custom animation at the very end of the Timeline.
    The ActionList had:
    Character: Animate
    Method: Change Parameter Value
    Type: Bool
    Set as value: [checked]

    Though the method you described is ideal -- just setting the parameter / playing the custom animation before the Timeline begins eliminates the extra step of creating and setting up the Signal.
    Thank you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.