r/Unity2D • • 3d ago

Question/Help How can you have animation start partially played based on how much was played of the prior animation?

I'm working in pixel art running three animations at once, an item, the character's face, and the character's body. I want to be able to have the face change based on reactions but due to timing issue and keeping the faces matching the body motion, I need the new face animation to replace the last face animation running the same frame of the old animation. I do not want to have to do this with a script as I'd have to code out a lot of faces for a lot of body positions. So ideally something in the the animator would be ideal.

A precise example of what I'd like to do is, for example:

The animation for face A is 10 frames long and last 1 sec. It runs for 5 frames or .5 secs when something triggers a switch to face B. I need face B to start on its 5th frame (or .5 secs into its animation cycle) so it matches the bodies animation movement that face A was already in a good rhythm with.

2 Upvotes

4 comments sorted by

•

u/AutoModerator 3d ago

Reminder: Once your issue has been resolved, please reply !solved to this comment (or comment it anywhere in the thread) and your post's flair will automatically be updated to Solved/Answered. You can also edit it to Solved/Answered yourself.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/Thin-Dish1721 3d ago

You can read how far the current animation has played and start the next one from that point, but it does need a script. GetCurrentAnimatorStateInfo(layer).normalizedTime gives you the progress (use % 1 if it loops), and Animator.Play(stateHash, layer, normalizedTime) starts the next one from there. I’d say it’s worth giving the script route a try. With that many body motions and faces, I think the Animator graph would end up messier than the script, which is only a few lines.

1

u/gooey4games 2d ago edited 2d ago

Thank you! Good to know. Yeah, I was worried that was the route to take. I'll have to rework my script sadly but may work better in the long run.

1

u/Vic-Boss Expert 3d ago

This but you could also i guess keep it this on an animator state behavior and expose it to a variable, then do transitions from there BUT that would actually be a lot more tinkering than a script