0
\$\begingroup\$

I'm making a simple card game, with some cards laying on the table. I want to flip the card when it's clicked, so I thought I'd use an animation to do it (lift card up in the air, rotate it and lower it back down). It works as I want with one card, but when I save it as a prefab and instantiate another one next to it, the card (obviously) moves to the same position as the prefab (as the animation stores global position I guess).

Is there any way to make animations in local space, or is there any other way I should do the flip?

\$\endgroup\$
  • 2
    \$\begingroup\$ Have you considered making an empty gameobject that's the parent of your card, animating your card relative to this parent, then positioning the parent where you want the animation to play from? \$\endgroup\$ – DMGregory Jul 15 '19 at 23:02
  • \$\begingroup\$ Awesome, thanks, that solved it =) \$\endgroup\$ – Skitskraj Jul 16 '19 at 14:38
  • \$\begingroup\$ Great! I'd recommend accepting TumayVarel's answer below then (click the checkmark icon near the top-left) \$\endgroup\$ – DMGregory Jul 16 '19 at 14:48
2
\$\begingroup\$

You can create an animation at an object that is child of an any other game object. When you create an animation at that child object, transform values of that animation will be created according to parent object. In that way when you want to add the same animation to other objects that are child of an object, the animation works with transform values that are set to that new parent object.

To remove confusion, I can say it like that. You want your animation to change the local transform values of a child object not its world transform values. Changing transform values of parent objects provide the change of the position of the target object and its animation.

| improve this answer | |
\$\endgroup\$

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.