• 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 roszek2 · Oct 23, 2020 at 05:43 PM · rotaterotatetowards

I am having trouble with quaternion rotate towards

I have an object that rotates at different times and different rotations and I can't figure out what to add for time to keep it from shuttering using rotate towards. How do I get/measure the time between each new rotation?

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 Klarzahs · Oct 23, 2020 at 11:14 PM 0
Share

If you call the rotateTowards withing Update(), you can use Time.DeltaTime to get the elapsed time in seconds from the last Update() call. Just multiply it within a lerp call

avatar image roszek2 Klarzahs · Oct 24, 2020 at 05:50 AM 0
Share

Could you give me an example of a lerp call or maybe a link?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Klarzahs · Oct 24, 2020 at 08:09 AM

Here is a code sample if you still need it:

 //calculate target vector
 Vector3 vec = (targetGO.transform.position - transform.position).normalized;
 //interpolate towards goal
 transform.forward = Vector3.Lerp(transform.forward, vec, Time.deltaTime * speed);

where speed defines your rotation speed.
Lerp(a, b, t) is a linear interpolation from a to b with parameter t. If t = 0, then it returns a, if t = 1 it returns b. If it is between 0<t<1, then it is linearly in between the two :)
You should normalize the targetvector, otherwise it will rotate faster is the goal point is far away.
Standard untested disclaimer

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
avatar image
0

Answer by roszek2 · Oct 25, 2020 at 03:55 PM

Where you have speed I don't have a constant speed with different forces being applied to the object. That's what I need to figure out I think.

There is a main object that moves and rotates based on forces applied to it's RigidBody and a clone of that object that needs to equal that movement. The object clone receives a position and rotation from the main object only. How would I get the maxDegreesDelta that Quaternion.RotateTowards and Vector3.MoveTowards calls for, which would vary in my case?

Comment
Add comment · Show 2 · 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 Klarzahs · Oct 26, 2020 at 08:12 AM 0
Share

Do you your second object to instantly copy the position/rotation of your main object? You could simply use

 void Update(){
   secondObject.transform.position = firstObject.transform.position;
   secondObject.transform.rotation = firstObject.transform.rotation;
 }

If you want to rotate it slowly, you can rate limit it by checking the angle between vectors and apply a $$anonymous$$(angle, maxDegreesDelta) function call. Position is similar, just check the distance and have a maximum

avatar image roszek2 Klarzahs · Oct 26, 2020 at 05:40 PM 0
Share

Yeah, that makes sense. 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

141 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 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 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 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 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 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 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

Rotate player to joystick sprite location 0 Answers

Smooth Camera Rotation After 2 Seconds 0 Answers

RotateTowards & Space.World 0 Answers

Rotate Towards doesnt work as expected 2 Answers

Flying player Rotates in the left and right direction not forward and back 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