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 PsychoHead · Mar 02, 2014 at 07:40 PM · rotationquaternionaxisplaneeulerangles

Rotating on a plane

I have a plane that I want to adjust my gameobject to while keeping the ability to rotate around the (new) local Y-axis. Therefore I calculated the planes normal (curUp) and planned on rotating the transform.up towards it.

 Quaternion rot = Quaternion.FromToRotation(transform.up, curUp);
 transform.Rotate(rot.eulerAngles.x, 0, rot.eulerAngles.z, Space.World);

That does not work as intended obviously, since I'm setting the global y axis to 0. However every attempt to transform the rotation into local space and setting the local y rotation to 0 results in a mess. What's the correct way of doing this in Unity?

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

2 Replies

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

Answer by robertbu · Mar 03, 2014 at 12:57 AM

Assuming you have a specific angle you are modifying to rotate your game object, try doing it this way:

 transform.up = curUp;
 transform.rotation = Quaternion.AngleAxis(angle, transform.up) * transform.rotation;
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 PsychoHead · Mar 06, 2014 at 02:33 PM 0
Share

Hey, thanks for your answer! For some reason I thought transform.up was read only. Good to know! However this method also applies a rotation around the local y axis in some cases.

avatar image robertbu · Mar 06, 2014 at 03:26 PM 0
Share

Have never sen the 'local y' issue, but I don't use this line very often. Here is an alternate for that line:

  transform.rotation = Quaternion.FromToRotation(transform.up, curUp) * transform.rotation;
avatar image PsychoHead · Mar 06, 2014 at 03:58 PM 0
Share

Thank you robertbu, works like a charm! So what was the problem on my own countless attempts? I used transform.rotation = transform.rotation * Quaternion.FromToRotation(transform.up, curUp); ins$$anonymous$$d of transform.rotation = Quaternion.FromToRotation(transform.up, curUp) * transform.rotation;

I probably could have avoided that with a little insight on Quaternions.

avatar image
0

Answer by PlasticGlasses · Feb 03, 2021 at 05:07 PM

Simple code to make, transform and rotate a plane

             GameObject thisPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); //create plane
             thisPlane.transform.position = new Vector3(1, 1, 1); //set position
             thisPlane.transform.Rotate(-90, 0, 0); //set rotation  
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.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Code to rotate around a local axis until local Y is 0? 0 Answers

Tank urret rotation - Need help. 1 Answer

2D animation : problem with rotation interpolation 1 Answer

Finding the Euler angles of an object's rotation in terms of a different set of axes 0 Answers

Edited mouselook script rotation clamp not working 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