Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ashitpro · May 31, 2016 at 07:36 PM · 2d spritesrotations

Rotate a sprite ( card ) until it reaches the destination?

I am making a card game. I am trying to create an effect when player plays his/her card. I would like to rotate the card as it moves to the destination ( another gameObject in middle of the board ). When card reaches the destination it should be aligned with the destination's rotation.

I tried following code without success. The card seems to rotate as long as it reaches the destination's rotation. I want continious rotation

 void Start(){
     rotateAtoB=true;
     startDistance=Vector3.Distance(transform.position,endPos.transform.position);
 }
 
 void Update(){
     if(rotateAtoB){
         float delta= 1 - Mathf.Pow(Vector3.Distance(transform.position,endPos.transform.position)/startDistance,5.0f/9.0f);
         transform.rotation=Quaternion.Slerp(transform.rotation,endPos.transform.rotation,(delta/startDistance)*1.0f);
 
         if(Mathf.Approximately(delta,1)){
             rotateAtoB=false;
         }
     }
     transform.position=Vector3.MoveTowards(transform.position,endPos.transform.position,2.0f*Time.deltaTime);
 }

I am also thinking about AddTorque method, but not sure if this is what I want. Any ideas how to move forward?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Soos621 · May 31, 2016 at 08:17 PM

I would suggest use a tween script to move the card to the board this will alliw you to easily animate the movement as for the rotation you seem to have the correct script going with the quaternion.slerp but I wouldn't set the sleeps variable to 1 set it to something like .1 at first this will rotate the card more slowly

Itween is available for free on the unity asset store

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Preserving the players rotation on rotating platforms 0 Answers

Flipping Sprite Renderer as of unity 5.3 with negative scale effects lighting when using bump map. 2 Answers

Linear speed in one direction 0 Answers

Polygon Collider 2D in 3D space missmatch 0 Answers

Game (2D) not rendering at all 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