Search Unity

Question Most efficient means for animating cards being dealt

Discussion in 'Animation' started by shisaaro, May 27, 2023.

  1. shisaaro

    shisaaro

    Joined:
    May 23, 2023
    Posts:
    4
    Hi there fellow creators!

    I'm in the process of creating my first game ( a card game). I want to animate each card being dealt and I'm wondering if there is a sneaky highly efficient way to accomplish this that I don't know about. Currently the practical, albeit ugly solution that I have in mind is to simply create a separate animation clip for each of the 48 cards in the deck since they each have different coordinates as destinations on my screen.

    When posting your replies please keep in mind that I know absolutely nothing about C# coding and I have somehow gotten by strictly on visual scripting. Thanks so much and I look forward to your enlightenment!
     
  2. shisaaro

    shisaaro

    Joined:
    May 23, 2023
    Posts:
    4
    Okay, so after doing a bit more research I discovered animation curves, and i discovered a visual scripting node to add a key to an animation curve. Am I on the right track?
     
  3. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,445
    The word "tweening" in animation means to take some object or figure and move it from a known starting position to a known ending position. It comes from deciding where the object is in between those endpoints for each frame of the animation.

    There are whole libraries devoted to tweening (leantween, dotween, itween, etc.). You could check those out, some are even free. But the concept is really straightforward, and they all boil down to using math functions like Mathf.Lerp and Mathf.SmoothStep and Mathf.MoveTowards to calculate the values you need in between the endpoints. The visual scripting nodes will have similar access.

    Your suggestion to use an AnimationCurve is a good one, it works in tandem with Mathf.Lerp to make animations that aren't so linear. Time moves at a constant rate but how you want to accelerate the motion and turning of cards can be adjusted nicely with an AnimationCurve. Start with a nice linear motion, get that working, and then use an AnimationCurve to alter the way the linear motion behaves.
     
    shisaaro likes this.
  4. shisaaro

    shisaaro

    Joined:
    May 23, 2023
    Posts:
    4
    thank you so much for your thoughtful reply. It does go quite a bit deeper than what I was looking for, but it's definitely good advice! I actually figured out what I was going for on my own I think. As far as dealing the cards at the beginning of the game to each spot I want to deal them to I decided it would probably be a good idea to just make an AOT library of curves, and then pull each curve from that list as the cards spawn. That way I can have one animation clip and just change the curves instead of making a whole new clip.