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 /
avatar image
0
Question by NinjaSIM37 · Apr 02, 2017 at 09:56 AM · transformvector3quaternion

How do I find the correct speed when using Vector3.MoveTowards and Quaternion.RotateTowards together?

I'm using a Coroutine that moves, rotates, and scales one transform into another transform using Vector3.MoveTowards and Quaternion.RotateTowards.

What I'd like to do is measure the amount of change each of these operations requires and set the speeds so that they all complete at (roughly) the same frame.

I have a struct that stores 3 floats for the respective speeds. As a bonus, it would be nice to have an "overall speed" float that could be adjusted to control how quickly all three changes are made.

 IEnumerator MorphTransform(Transform final, Speeds speeds)
     {
         while(transform.position != final.position || 
                 transform.rotation != final.rotation || 
                 transform.localScale != final.localScale)
         {
             transform.position = Vector3.MoveTowards(transform.position, 
                                                     final.position, 
                                                     speeds.transposeSpeed * Time.deltaTime);
 
             transform.rotation = Quaternion.RotateTowards(transform.rotation, 
                                                             final.rotation, 
                                                             speeds.rotateSpeed * Time.deltaTime);
 
             transform.localScale = Vector3.MoveTowards(transform.localScale, 
                                                         final.localScale, 
                                                         speeds.scaleSpeed * Time.deltaTime);
             yield return null;
 
         }
     }
 
     [System.Serializable]
     public struct Speeds
     {
         public float transposeSpeed;
         public float rotateSpeed;
         public float scaleSpeed;
     }

Thanks for your time and response in advance!

Comment
Add comment · Show 1
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 RobAnthem · Apr 02, 2017 at 10:06 AM 0
Share

This doesn't make sense, your coroutine doesn't perform like a coroutine, it just runs once then it's done. Without a yield for seconds it isn't going to perform much action. Also, movetowards is a bit like a lerp, so it's kind of useless without being scaled itself. Honestly I'd just use a basic Vector3.Lerp, and Quaternion.Slerp. You can scale both by the same time scale and it would be a breeze. If you don't know how lerps work, here is a quick example. Remember this is only an example, but you should get the idea.

 Vector3 startPos;
 Vector3.endPos;
 float scale;
 
 void LerpVector(float time)
 {
     scale += time;
     transform.position = Vector3.Lerp(startPos, endPos, scale);
 }

0 Replies

· Add your reply
  • Sort: 

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

c# modify only one axis of a quaternion 2 Answers

How to smoothly rotate to certain directions using input axis 1 Answer

Transform a Vector by a Quaternion 1 Answer

Finding direction of objects movement, and playing an anim specific to it 0 Answers

Unity Rotate Raycast on Quaternion 1 Answer


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