Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Michael_R · Sep 30, 2019 at 06:58 PM · vector3quaternionsource code

Whats the source code of Quaternion.FromToRotation?

Hello,

id like to know the source code of FromToRotation, or if someone knows the FromToRotation equivalent of ue4 c++ would be better ; )

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

Answer by Bunny83 · Sep 30, 2019 at 07:14 PM

How is that relevant? That's a pure mathematical thing. It's probably just something along the lines:

 public static Quaternion FromToRotation(Vector3 aFrom, Vector3 aTo)
 {
     Vector3 axis = Vector3.Cross(aFrom, aTo);
     float angle = Vector3.Angle(aFrom, aTo);
     return Quaternion.AngleAxis(angle, axis.normalized);
 }

Of course AngleAxis should be pretty straight forward as well

 public static Quaternion AngleAxis(float aAngle, Vector3 aAxis)
 {
     aAxis.Normalize();
     float rad = aAngle * Mathf.Deg2Rad * 0.5f;
     aAxis *= Mathf.Sin(rad);
     return new Quaternion(aAxis.x, aAxis.y, aAxis.z, Mathf.Cos(rad));
 }

All untested.

Comment
Add comment · Show 12 · 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 Michael_R · Sep 30, 2019 at 07:42 PM 0
Share

@Bunny83 Thanks its working, as i mentioned i mainly search for a c++ equivalent of it but cause i havent found one ill try get the source of it to ue4 c++.

avatar image Bunny83 Michael_R · Sep 30, 2019 at 08:08 PM 0
Share

Why do you ask unreal related questions on Unity answers? Please note that Unity answers is for questions related to development with the Unity engine. Abusing this site might get your account banned. I see you asked several questions about unreal already . It's a bit impudent to ask such questions here.

avatar image Michael_R Bunny83 · Sep 30, 2019 at 08:19 PM 0
Share

Sry, I did not think anything about it. I thought its ok cause there isnt really a website for command equivalents.

Show more comments
avatar image iamarugin · Sep 06, 2020 at 08:44 AM 0
Share

This code doesn't handle the case, when two vectors are in the opposite direction.

avatar image PraetorBlue iamarugin · Oct 15, 2020 at 10:06 PM 1
Share

That's because it's a degenerate case. There are infinite solutions when the vectors are opposite.

avatar image iamarugin PraetorBlue · Oct 16, 2020 at 06:42 AM 0
Share

II understand, but Unity's Quaternion.FromToRotation somehow handled these cases and return 180 degrees rotations.

Show more comments

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

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

Related Questions

How to use Quaternion to rotate an object in only one axis? 1 Answer

Planetoid Gravity 1 Answer

Perpendicular Vector3 0 Answers

Angles from quaternion/vector Problem. 2 Answers

How would I smooth out a Quaternion? 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