Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
1
Question by AzovUa · Jul 17, 2014 at 11:22 AM · rotationrotateflyinglocaleulerangles

localEulerAngles.x rotates as in world space

Hi! I'm making a game with flying pigeon on android with accelerometer contol, and i have a trouble with rotating it in local space. Everything is allright when i'm flying straight and want to turn up or down (around X axis in local space).

When i want to turn left or right, firstly i need to lean to one side (rotate around z axis - blue arrow), and then to rotate around X axis in local space (red arrow).

alt text

But when i rotate around X axis in local space, it turns up, just as in world space! (red arrow, wanted rotation - green arrow)

alt text

Here is code i use to rotate it:

 transform.localEulerAngles = new Vector3 (-Input.acceleration.z * rotationAngle,    
                                    transform.localEulerAngles.y,
                                   -Input.acceleration.x * rotationAngle);

It gives the same result as using transform.eulerAngles and transform.localRotation gives the same result as transform.rotation

transform.Rotate with local space works properly, but it's not suitable for accelerometer control. What's the problem?

screen2.jpg (36.5 kB)
screen3.jpg (30.0 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
0

Answer by Bunny83 · Jul 17, 2014 at 12:24 PM

Well, is your object actually a child of another object? If not ALL local properties are "local to the world" and do exactly the same as the world space properties. The Rotate method applies a relative rotation to your object. localEuerAngles (or localRotation) is an absolute rotation relative to the parent. Also euler angles have a fix order in which the rotations happens.

In Unity it's: z, x, y. You also shouldn't use eulerAngles for such a control as euler angles suffer from gimbal lock. It's better to directly use Quaternions. I would probably use a combination of LookRotation and AngleAxis to specify the initial rotation and a rotation based on the gravity vector.

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 AzovUa · Jul 18, 2014 at 01:03 AM 0
Share

Sorry, maybe i'm idiot, but i can't understand anything... I tried using Quaternions, but it also rotates in world space...

 float tiltAroundZ = acceleration.z * rotationAngle;
 float tiltAroundX = acceleration.x * rotationAngle;
 Quaternion rotX = Quaternion.AngleAxis (tiltAroundX, Vector3.right);
 Quaternion rotZ = Quaternion.AngleAxis (tiltAroundZ, Vector3.back);
 Quaternion lookRot = Quaternion.LookRotation (Vector3.forward, Vector3.up);
 Quaternion rot = rotX * rotZ * lookRot;
 transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime * smooth);



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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

localEulerAngles don't seem to work in an equasion 3 Answers

How to get all gameObjects with a script on them 1 Answer

Trouble rotating a prefab while it's moving up,Rotating an object with an animation while it moves up 0 Answers

Making a rotating object rotate with a parent object 1 Answer

After rotate with joystick, rotate resetting,joystick rotate correction 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