Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 GregoryFenn · Oct 31, 2021 at 06:40 PM · quaternionrolllocalrotationpitchyaw

Setting the roll of a rotation

This post (https://answers.unity.com/questions/416169/finding-pitchrollyaw-from-quaternions.html) talked about how to find the roll (and pitch and yaw) from a quaternion.

I need to do this opposite: how to SET the roll? For example, suppose I want a plane with a transform.rotation orientation to be allowed to pitch up and down, and yaw around the y-axis, but I want the roll to half every second (to give the feeling of it naturally aligning itself over time).

(I tried setting the transform.up to slowly drift towards Vector3.up, on each frame to ensure the plane is not rotated about the Z Axis, but of couse this also sets the pitch to zero too, which is not the intention.)

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
0

Answer by GregoryFenn · Oct 31, 2021 at 07:21 PM

I have a partial solution that isn't quite what I wanted but might be useful to people looking later.

My idea is to have a pair of gameobjects like a wing or a hand on the left and right of the main object as children. Then Unity can easily find the transform.position.y of these two wings. If it's 0, the plane has zero roll; if it is positive, the roll is between 0 and Pi; lastly if it's negative, the roll is between 0 and -Pi (maybe the other way around but you get the idea).

So we can use

 float RollMeasurer = RightWing.position.y - LeftWing.position.y;

with this operation:

 this.transform.Rotate(0, 0, SomeScaler * Time.deltaTime * RollMeasurer, Space.Self);

and this code will gradually (per Update() or FixedUpdate()), flatten out the roll of this.transform.

Comment
Add comment · Show 1 · 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 CodesCove · Nov 01, 2021 at 12:24 AM 0
Share

Don't know if this is suitable for your need but if I need to align anything to a specified rotation I usually use some reference transform.rotation to give the target rotation and then use Quaternion.RotateTowards inside Update to gradually align the rotation with the target.

https://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html

That way you don't need to care about direction (always the shortest path) and need only one reference

Hope you get it working

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

131 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

Related Questions

Convert directions in Vector3 to yaw/pitch/(roll),Converting directions in Vector3d to yaw/pitch/(roll) 0 Answers

Problems getting PID system and rotations to work together. 0 Answers

Get pitch and roll 0 Answers

Yaw, Pitch, Roll adjustments relative to object? 1 Answer

pitch yaw roll user input on an object? 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