Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Whelandrew · May 19, 2015 at 07:56 PM · lerpanglesanimatecards

Animate fanning cards almost works!

I have a list of cards set with a starting and ending position. When I simply place the cards, they are placed in the scene as a fanned-out deck. Like so:

alt text

I want to animate this so that the deck of cards moves along the angle and the cards drop into place to create the final look. For the most part, I have a function that does this, but I am having some conflicts with proper placement. Here the designed function.

I would also like to know the best way to turn the cards while they move along the arc. Thanks!

     IEnumerator AnimateCardSpread()
     {
 
         Vector3 newPos=memoryCards[0].startPos;
         int k=0;
 
         while(k<memoryCards.Count)//memoryCards is the List of card objects with established start/end positions
         {
             foreach(CardController c in memoryCards)
             {
                 //has the card reached it's endPos? 
                             //I THINK THIS IS WHERE THE PROBLEM LIES
                 if(c.endPos == newPos)
                 {
                     c.transform.position=newPos;
                 }
             }
 
             // calculate current time within our lerping time range
             float cTime = Time.time * 10f;
 
             // calculate straight-line lerp position:
             Vector3 currentPos = Vector3.Lerp(memoryCards[k].startPos, memoryCards[k].endPos,cTime);
             //Vector3 currentPos = Vector3.Lerp(new Vector3(-4,0,0), new Vector3(4,0,0), cTime);
             
             // add a value to Y, using Sine to give a curved trajectory in the Y direction
             currentPos.y += animSpeed * Mathf.Sin(Mathf.Clamp01(cTime) * Mathf.PI);
             
             // finally assign the computed position to our gameObject:
             newPos = currentPos;
 
             k++;
 
             yield return new WaitForSeconds(.02f);
         }
     }


Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Whelandrew · May 19, 2015 at 09:59 PM 0
Share

So, I was just overcomplicating things. Here is my solution:

     IEnumerator AnimateCardSpread()
     {
         int k=0;
         for(float i=0;i<1f;i+=animSpeed)
         {
             float cTime = Time.time * 10f;
 
             Vector3 currentPos = Vector3.Lerp(memoryCards[k].startPos, memoryCards[k].endPos,cTime);
             
             currentPos.y += animSpeed * $$anonymous$$athf.Sin($$anonymous$$athf.Clamp01(cTime) * $$anonymous$$athf.PI);
             
             memoryCards[k].transform.position=currentPos;
 
             if(k>=memoryCards.Count-1)
                 k=0;
             else
                 k++;
 
             yield return new WaitForSeconds(animSpeed);
         }
     }
avatar image hu90 · May 19, 2015 at 10:27 PM 0
Share

Please add it as an answer and mark it as a solution.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Whelandrew · May 19, 2015 at 10:29 PM

So, I was just overcomplicating things. Here is my solution:

  IEnumerator AnimateCardSpread()
  {
      int k=0;
      for(float i=0;i<1f;i+=animSpeed)
      {
          float cTime = Time.time * 10f;
 
          Vector3 currentPos = Vector3.Lerp(memoryCards[k].startPos, memoryCards[k].endPos,cTime);
          
          currentPos.y += animSpeed * Mathf.Sin(Mathf.Clamp01(cTime) * Mathf.PI);
          
          memoryCards[k].transform.position=currentPos;
 
          if(k>=memoryCards.Count-1)
              k=0;
          else
              k++;
 
          yield return new WaitForSeconds(animSpeed);
      }
  }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image moh05 · Dec 07, 2015 at 04:48 PM 0
Share

$$anonymous$$ay you explain where ti add this piece of code? thanks :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animate buttons on click. 2 Answers

How to Make a Scroll In Menu 2 Answers

Trouble coding a peeking system like in Rainbow Six Siege??? 1 Answer

Rotate children (Cards) on a panel (maybe using lerp, or another method?) 1 Answer

Asynchronously and smoothly move a 2D player character? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges