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
0
Question by weazel-art · Jun 27, 2012 at 11:33 AM · rotationvector3quaternionconvertcombine

combine / convert rotations (Quaternion and Vector3)

Hi, i've been trying to convert / combine two rotation transforms into one to stop them overriding each other.

 //----- tilts character to surfaces -----//
     transform.up = Vector3.Lerp(transform.up, surfaceNormal, Time.deltaTime * xRotSpeed);
     //----- tilts character to surfaces -----//
     
     //----- tilts left and right ------//
     transform.eulerAngles = Vector3(0, curAngle, 0);
     //----- tilts left and right ------//

I'm trying to either multiply / scale two together, to allow an X rotation to occur based on the surfaceNormal, or somehow convert the current Vector3.Lerp to allow me to extract a value to put into the X axis of the EulerAngles, as my character only has movement on the x and y (x for turning towards surfaces and y to rotate yaw based on forward velocity)

I hope you can help this hasgot me raging alot lately, tried so many Quaternion types and Vector scales and lerps its driving me nuts!

Thanks! Renn

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
1
Best Answer

Answer by Owen-Reynolds · Jun 27, 2012 at 03:30 PM

This is an untested variant of a working "angled with ground, but my spin" merged with your code. The way facingQ is created/used is probably the most interesting part:

 // your lerp to smooth into normal:
 Vector3 newUpV=Vector3.Lerp(transform.up,surfaceNormal,Time.deltaTime*xRotSpeed);
 // convert new up into a rotation:
 Quaternion newUpQ=Quaternion.FromToRotation(Vector3.up, newUpV);

 // your spinning:
 Quaternion facingQ=Quaternion.Euler(0,curAngle,0);

 // combine head tilt and spin:
 transform.rotation = newUpQ * facingQ;

The problem with setting transform.up then transform.eulerAngles is that there's no good way to say "keep the work from the last instruction." Building quaternions for each local spin lets you combine them with *. In this case, newUpQ is the tilt that takes from facing North, head up, to still facing north-ish, but head tilted to the target. Then *facingQ adds a local y-spin.

Comment
Add comment · Show 3 · 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 weazel-art · Jun 27, 2012 at 03:58 PM 0
Share

Thanks Owen, this worked perfectly, what you said about "building quaternion for each spin" only brings another question which is what is the difference between a quaternion and a vector (is it one is x,y,z, and one is x,y,z,w?)

Its something i will have to learn properly but a quick explanation would be grand, seeing as you understand that process clearly (as it worked a charm)

Thanks again, i now know you can multiply quaternions together to allow rotations on multiple axis ^_^

avatar image Owen-Reynolds · Jun 27, 2012 at 04:17 PM 0
Share

The x/y/z of Quats is just book-keeping stuff, with no useful meaning. A Quaternion is a complete "rotation/facing," ready to be assigned to your rotation. You could think of a Quat as a magic wand waved over the vector you want to face, plus the extra "spin" around it (the wand part makes it count as a rotation.)

A vector could be a way you want to be facing. If you use Quaternion Q=Quaternion.LookRotation(V), then Q is that facing (with your head spun "up".)

avatar image Wolfram · Jun 27, 2012 at 05:17 PM 0
Share

The x/y/z/w quaternion notation has no simple/obvious "real world" representation, most notably the "x/y/z" is not directly related to actual X/Y/Z axes/rotations, it's just a way of accessing the Quaternion's members. You can convert a Quaternion into an axis+angle representation (where x/y/z would define the rotation axis, and w the angle around that axis), but that's not how quaternions are stored in Unity, and there is no trivial conversion (it involves asin/acos and sqrt).

If you must know, quaternions are represented in a 4-dimensional complex space :-P (and even that isn't the mathematically sound interpretation).

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

how to convert the angle to roatation? 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

Connecting transform with Vector3 4 Answers

Planetoid Gravity 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