0
\$\begingroup\$

I was looking for a way to create simple transform animations for 2d objects. As example, I wanted to animate all the objects of the scene when the game is paused (i.e. I just want to move the objects outside the screen boundaries with a nice animation). I think that creating an Animator Controller for something like this is not really useful for two reasons:

  1. I don't know where the objects are at runtime. Please correct me if I'm wrong, I think I cannot dynamically change the value of a keyframe attached to an animation controller, so if I just start a transform animation the sprite will jump at the first keyframe value and then performs the animation. Terrible result.

  2. If I have 200 objects I should create 200 animation controllers with 200 animations.

Creating animation programmatically would be great, but I read on forums and here on stackexchange that you cannot dynamically handle keyframes... and that I HAVE to use the Animation Controller, otherwise I can use the Legacy animation system (that to me sounds so... deprecated :P)

Then I checked this page of the documentation: http://docs.unity3d.com/ScriptReference/Animation.html

They talk about the "Animation" component... and they don't say this element is Legacy/Deprecated. Looking at this page it seems that I have a lot of control over Animation actually... but know I'm completely confused! Is this component deprecated or not? Should I always use the Animation Controller instead?

\$\endgroup\$
6
  • \$\begingroup\$ I think Animation component is not deprecated as if it is so, then official documentation must mentioned that there. Also as an alternative, you can use iTween \$\endgroup\$ Commented Feb 29, 2016 at 6:54
  • \$\begingroup\$ But if you attach an "animation" to a GameObject automatically you get an animation controller.... What does that mean? :/ And if you attach the animation through the "add component" button, you have to mark the animation as legacy. \$\endgroup\$
    – MatterGoal
    Commented Feb 29, 2016 at 7:03
  • \$\begingroup\$ 1- Because Animator Controller controls the Animations. 2- I was not that in, in Animation component. But the definition Legecy is, the component or element that is deprecated but the most useful element and still popular among users. \$\endgroup\$ Commented Feb 29, 2016 at 7:13
  • \$\begingroup\$ GameObjects can share animation controllers so you wouldn't need 200 of them necessarily. I'm not too sure what you mean by your first point - you can trigger a transition in your animation controller, start playing the animation and program the object to move upwards... What's the problem? \$\endgroup\$
    – zcabjro
    Commented Feb 29, 2016 at 10:51
  • \$\begingroup\$ @Jack the problem is that if I want to animate the position of the object let's say from 10,10 to 30,30 I should have an object already placed in 10,10 otherwise, as soon as the animation starts the object will jump to 10,10 from its current position. An example of usage: during the game play I have 10 objects moving randomly around the screen, when I pause the game I want these objects to move to an arbitrary position x,y. I cannot perform these animations using the animation controller... and this is a shame since there I might easily adopt animation curves. \$\endgroup\$
    – MatterGoal
    Commented Feb 29, 2016 at 21:06

2 Answers 2

1
\$\begingroup\$

I would accomplish it by adding an Animator component and an animation clip I wanted to play for the duration of the motion (e.g. a helicopter flying off would play an appropriate animation clip where the blades spin faster or the helicopter angles itself and so on).

I would then code the movement itself with a simple script or by allowing an existing movement script to do it.

private bool animateExit = false;

private void Update()
{
    if(animateExit)
    {
        AdjustPosition(1f, 1f);
    }
}

public void AnimateExit()
{
    // plays the exit animation
    GetComponent<Animator>().SetBool("exit", true);
    animateExit = true;
}

// handles the movement
private void AdjustPosition(float x, float y)
{
    transform.position += new Vector3(x, y, 0f) * Time.deltaTime;
}
\$\endgroup\$
0
\$\begingroup\$

To use old animation component click on your model and set animation to legacy then remove any animation controllers from it and add and animation component. Yeah I think in your case it will be better but check out animation override controller , its use when objects have same animations and you dont have to make same controllers again and again .

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .