• 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
1
Question by omg_Aya · Aug 20, 2013 at 07:36 PM · rotateprediction

How to rotate a Quaternion based on angularVelocity?

Hello,

So I am trying to do client side prediction for rotations. The way I was thinking this would work is similar to how I did the position prediction. The only problems is I can't seem to find a way to rotate my syncRotation Quaternion by the angularVelocity Vector3. I tried syncRotation*=angularVelocity, but I get a compiler error saying it can't convert from Vector3 to Quaternion. Here's the code for what I'm doing:

 void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
 {
     Vector3 syncPosition = Vector3.zero;
     Vector3 syncVelocity = Vector3.zero;
     Quaternion syncRotation = Quaternion.identity;
     Vector3 syncAngularVelocity = Vector3.zero;
     
         
     if (stream.isWriting)
     {
         syncPosition = rigidbody.position;
         stream.Serialize(ref syncPosition);
  
         syncVelocity = rigidbody.velocity;
         stream.Serialize(ref syncVelocity);
             
         syncRotation=rigidbody.rotation;
         stream.Serialize(ref syncRotation);
             
         syncAngularVelocity=rigidbody.angularVelocity;
         stream.Serialize(ref syncAngularVelocity);
     }
     else
     {
         stream.Serialize(ref syncPosition);
         stream.Serialize(ref syncVelocity);
          stream.Serialize(ref syncRotation);
         stream.Serialize(ref syncAngularVelocity);
         syncTime = 0f;
         syncDelay = Time.time - lastSynchronizationTime;
         lastSynchronizationTime = Time.time;
  
         syncEndPosition = syncPosition + syncVelocity * syncDelay;
         syncStartPosition = rigidbody.position;
         syncRotation*=(syncAngularVelocity*syncDelay);
         syncEndRotation = syncRotation;  
         syncStartRotation = rigidbody.rotation;
             
         //rigidbody.rotation=syncrotation
             
     }
 }
     
     
     private void SyncedMovement()
 {
     syncTime += Time.deltaTime;
     rigidbody.position = Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay);
     rigidbody.rotation = Quaternion.Lerp(syncStartRotation,syncEndRotation,syncTime/syncDelay);
 }

Anybody know of a good way to convert from Vector3 to a Quaternion or just a better way to do what I am trying to do? Thanks.

Comment
Add comment · Show 4
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 robertbu · Aug 20, 2013 at 08:01 PM 0
Share

I don't have time at the moment to really think through your problem, but here are a few comments. $$anonymous$$ultiplying a Vector3 by a Quaternion gives back a Vector3:

 Vector3 = Quaternion * Vector3;

$$anonymous$$ultiplying a Vector3 by a Quaternion is illegal:

 Illegal = Vector3 * Quaternion;

If you got your angular velocity from the Rigidbody, the angles are in Radians. So what you may want:

 syncRotation = Quaternion.Euler(syncAngularVelocity * syncDelay * $$anonymous$$athf.Rad2Deg) * syncRotation;
avatar image omg_Aya · Aug 20, 2013 at 08:37 PM 0
Share

Thanks! I will try this out!

avatar image robertbu · Aug 20, 2013 at 09:23 PM 0
Share

One other point. Order matters when you combine Quaternions.

For a regular multiplication, "`x = y`" is equivalent to "`x = x y`". This may also be true for Quaternions, and I think for your particular problem the combination you want "`x = y x`". And therefore you want to do the multiplication as I've done, and not use the '`=`' short form.

avatar image MarkusA380 · Aug 09, 2015 at 02:00 PM 0
Share

angularVelocity is not an Euler Angle. You need to work with Quaternion.AngleAxis. Also be careful that Quaternion multiplication is noncommutative. So add the AngleAxis Quaternion first and multiply it with the old rotation.

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by dood2 · Aug 20, 2013 at 07:53 PM

Try this:

syncRotation = Quaternion.Euler(syncAngularVelocity syncDelay);

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Camera rotation around player while following. 6 Answers

Get object orientation 3 Answers

Rotating object towards mouse point 1 Answer

Doesn't Add Rotation Over 180 2 Answers

How can I rotate an elliptical cloud of points? 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