0
\$\begingroup\$

Goal

One might use a coroutine to interpolate an object's position from point A to point B.

What I'm trying to do is store that interpolation as a Unity Animation file, but have the ability to manually enter points A and B each time it plays.

Description

I have a simple Animation — a "jump", if you will — which I want to chain with the aforementioned interpolation:

  • the object does a little jump;
  • mid-air, the object moves/interpolates to another position.

Of course, I could do this by playing the coroutine after the first animation is done, but it'd be cleaner to store both as Animation files and use an Animator Controller to manage them, especially since the 2 animations are technically parts of one whole.

Is that possible?

If so, how could I record/create it? If not, what's a clean alternative?

\$\endgroup\$
0
\$\begingroup\$

It sounds like what you want is Animation Parameters.

Animation Parameters are variables that are defined within an Animator Controller that can be accessed and assigned values from scripts. This is how a script can control or affect the flow of the state machine. [...] For example, a script can set a parameter to control a Blend Tree.

Parameters can also be used to control animation speed, etc.

\$\endgroup\$
  • 4
    \$\begingroup\$ This answer would be better if it demonstrated how to use animation parameters to bring the object to a specific target position as described in the question. \$\endgroup\$ – DMGregory Aug 19 '20 at 16:46
  • \$\begingroup\$ Sorry for the late reply (was working on other features) but how would that work? You can't define a Vector2 parameter, so how else would you specify what position to animate to? \$\endgroup\$ – verified_tinker Aug 21 '20 at 9:18
  • \$\begingroup\$ @verified_tinker Good point, didn't fully think this through. In that case I'd say you're best off using a coroutine. \$\endgroup\$ – Kevin Aug 21 '20 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.