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 Daniel Greenhorn · Feb 21, 2015 at 07:12 PM · rotationlocalglobalcombinelocalrotation

Combining 2 Rotations: Global and Local

Here is the problem: ship on the sea (XY plane).Ship turns left right ok. When turning I want the ship to heel (rotate a little along the longitudinal axis).

Left right turning works ok with this code:

  var rotationVector = GameObject.Find ("SHIP").transform.rotation.eulerAngles;
     rotationVector.x = 0f;
     rotationVector.y = 0f;
     rotationVector.z =  rotationVector.z + 0.5f; //well , a function anyway
     GameObject.Find ("SHIP").transform.rotation = Quaternion.Euler(rotationVector);

If I try to add the second rotation on the Y axis (the heeling), the resultant rotation gets weird.

  var rotationVector = GameObject.Find ("SHIP").transform.rotation.eulerAngles;
     rotationVector.x = 0f;
     rotationVector.y = rotationVector.y+ 0.5f;
     rotationVector.z =  rotationVector.z + 0.5f;
     GameObject.Find ("SHIP").transform.rotation = Quaternion.Euler(rotationVector);

As far as I get it, the rotation is local, and heeling takes steering off the horizontal and the ship goes either airplane or submarine. I could make an Z adjustment each frame to compensate but I don't get the heeling! Tried 2 rotations stages, tried fist one then the other, variants from forums but I can't get it working..

How to get the banking local and the turning global on the same object?

This is getting me bugnuts Heelp!?!

Comment
Add comment · Show 2
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 vintar · Feb 21, 2015 at 09:05 PM 0
Share

transform.localRotation to set the local rotation. But why is the rotation local? Is the ship a child of something?

avatar image Daniel Greenhorn · Feb 22, 2015 at 07:27 AM 0
Share

Hello, The ship is not a child of anything. Excluding the blend model, it's a new rectangle that I want to move like in this photoalt text

I am attaching a txt file that you can paste into a script to illustrate my problem. Just attach it to the camera.link text

If I'm doing it backwards (as I'm probably doing) please someone send me the code for doing it right!!

Thanks!

turn-and-heel-code.txt (19.0 kB)
steer-and-heel.jpg (14.0 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Paulius-Liekis · Feb 22, 2015 at 10:07 AM

It might be that the order of rotations is different than you expect. Try this (of flip the order to y/z quaternions):

 GameObject.Find ("SHIP").transform.rotation = 
    Quaternion.Euler(new Vector3(0, rotY, 0)) * 
    Quaternion.Euler(new Vector3(0, 0, rotZ));

 

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

Answer by Daniel Greenhorn · Feb 22, 2015 at 04:14 PM

It turns out the solution was

  GameObject.Find ("SHIP5").transform.rotation = Quaternion.AngleAxis(rudder5, Vector3.forward)*Quaternion.AngleAxis(heel5, Vector3.up);
 

alt text

Well, the angle changes from 0 to 360 and from 360 to 0 when passing 0 but that can be dealt with with a ton of IF's for both rudder and heel angles.

For anyone having this problem, I'm attaching the whole code

link text


steer-and-heel-done.jpg (3.6 kB)
turn-and-heel-code-solved.txt (15.4 kB)
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

22 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

Related Questions

Local Rotation and then Global Rotation 1 Answer

Simulating different gravity, how to make falling platform fall in the desired direction? 1 Answer

Importing a armature from blender to unity ruins the models rotations -1 Answers

Why is it moving locally instead of globally? 1 Answer

Is there a way to use MoveRotation() globally? 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