Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 jeroenvdv · Feb 19, 2018 at 12:55 AM · rotationquaternionlocalrotation

Copy local rotation on one axis of A to B

I've got an IMU controlling the rotation of the cube (on the right) via a Quaternion, works perfect..

I would like to copy only the localRotation around the red axis (for example the Transform.forward axis) of the cube, to the red axis on the plane (on the left).

If for example the rotation around the blue axis of the cube changes (via the IMU), the rotation of the plane shouldn't change.

I can't get my head around this one!

alt text

unity-axisrotation.png (86.1 kB)
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
3
Best Answer

Answer by hrishihawk · Feb 19, 2018 at 12:31 PM

You could do it by taking Hadamard Product of desired axis of rotation for the plane and Euler angle component of the cube.Doing that will eliminate the values in all other axes than the desired one .And then update the plane's rotation with the newly obtained vector.

 v1 = (x, y, z)
 v2 =transform.forward =(0, 0, 1)
 Hadamard product of v1 and v2 gives (0, 0, z)

I have done the following implementation.Take a look and I hope it helps.

 public class HandleRotation : MonoBehaviour
 {
     public Transform _CubeTransform;
     public Transform _QuadTransform;
 
     
     void Update () {
         //Controllig the Cube's rotation with keyboard
         if(Input.GetKey(KeyCode.A))
             _CubeTransform.Rotate(_CubeTransform.forward,Space.Self);
         if(Input.GetKey(KeyCode.D))
             _CubeTransform.Rotate(_CubeTransform.forward*-1,Space.Self);        
         if(Input.GetKey(KeyCode.W))
             _CubeTransform.Rotate(_CubeTransform.up,Space.Self);
         if(Input.GetKey(KeyCode.S))
             _CubeTransform.Rotate(_CubeTransform.up*-1,Space.Self);
         //Update quad's rotation in the desired axis (Vector3.forward here )
         UpdateRotation(_QuadTransform,_QuadTransform.forward);
         print(transform.forward);
     }
         
     private void UpdateRotation(Transform target,Vector3 axis)
     {
         Vector3 rot = _CubeTransform.rotation.eulerAngles;
         rot = Hadamard(rot,axis);
         target.rotation = Quaternion.Euler(rot);
     }
 
     //returns hadamard product of two vectors
     private Vector3 Hadamard(Vector3 v1, Vector3 v2)
     {
         return new Vector3(v1.x*v2.x,v1.y*v2.y,v1.z*v2.z);
     }
 }

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 jeroenvdv · Feb 20, 2018 at 08:34 AM 0
Share

Thanks for your great answer, Hrishikesh! Works perfect - and I kind of understand why!

This is where math gets quite complicated (.... Quaternions, matrices, vectors).. :)

avatar image hrishihawk jeroenvdv · Feb 20, 2018 at 08:57 AM 1
Share

Glad I was able to help.Cheers :)

avatar image hrishihawk · Feb 20, 2018 at 09:02 AM 1
Share

It'd be great if you could close this question by choosing this as right answer.

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

104 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

Related Questions

Child versus Parent rotations 3 Answers

transform.localRotation resets after rotation 1 Answer

how to apply overall rotation to collection of rotated objects 0 Answers

How to control player camera on angled surface/independent of xyz axis? 1 Answer

Unity Simulate Local Rotation 0 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