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
2
Question by lvictorino · Jun 23, 2012 at 11:13 AM · rotationvector3quaternionlerpcomparison

How to know if a gameobject is rotating?

Hello,

I have a GameObject (a cube), and I make it rotate on X or Y axis.

I use a Quaternion.Lerp to "animate" its moves. However I'd like to wait before it has finished its rotation before asking him to rotate another time. That's why I'd like to know how to be sure to quaternion are equals.

First I tried with the Quaternion's == operator (as mentionned in the documentation):

 if ( final_rotation == transform.rotation )  

But sometimes it returned me false even after the Lerp has finished for a long time. So I tried testing the Vector3 values:

 if ( final_rotation.eulerAngles == transform.rotation.eulerAngles )

And it sometimes give me the same result : it returns me false even if Debug.Log returns me the same result.

I think it's something in relation to float precision, but I can't find how to deal with it. Thank you 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 Fattie · Jun 23, 2012 at 08:13 PM 0
Share

Why are you doing all this?

Don't forget unity IS A GA$$anonymous$$E ENGINE .. it has full physics built in. You do not need to do any of this. Good news!

Just add some force (torque in this case) and PhysX does everything.

1 Reply

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

Answer by whydoidoit · Jun 23, 2012 at 11:16 AM

The problem with Slerp is it can take a really long time to finish, especially using a Time.deltaTime calculation. You are probably better off checking for a small difference in the angles:

  if((final_rotation.eulerAngles - transform.rotation.eulerAngles).sqrMagnitude < 0.1) {
     ...
  }
Comment
Add comment · Show 4 · 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 lvictorino · Jun 23, 2012 at 11:18 AM 0
Share

For the second time of the day: thank you. I have to read those maths books.

avatar image whydoidoit · Jun 23, 2012 at 11:21 AM 1
Share

The only one to read if you ask me is $$anonymous$$athematics for 3D Game Program$$anonymous$$g and Computer Graphics - my math bible :) In truth I'm pretty hopeless at $$anonymous$$ath (at least mathematical notation) but the stuff you need isn't so bad, I get most of it by playing around and Google...

avatar image lvictorino · Jun 23, 2012 at 08:15 PM 0
Share

This is exactly what I've began to read few days ago. That's reassuring :)

avatar image Fattie · Jun 23, 2012 at 08:19 PM 0
Share

hey, what about

Real-Time Rendering $$anonymous$$as Akenine-$$anonymous$$oller

Real-Time Collision Detection Christer Ericson

The (New) Turing Omnibus: 66 Excursions in Computer Science DEWDNEY

sed:

$$anonymous$$athematics for 3D Game Program$$anonymous$$g and Computer Graphics John Flynt, Eric Lengyel

I also strongly recommend

Les Demoiselles de Rochefort. Catherine Deneuve, et al

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Issues with Lerps 2 Answers

How would I smooth out a Quaternion? 2 Answers

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

Rotating a direction Vector3 by Quaternion 2 Answers

Set rotation based on 1,1,1 style vector? How to convert vector3 to 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