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 /
  • Help Room /
avatar image
0
Question by tperry1x · Dec 17, 2015 at 11:51 PM · rotationrotation axislocalrotation

Rotation does not seem to make sense

I have an empty gameobject which is in front of the player (so wherever he moves, the gameobject is dead ahead).

There are tumbling cubes falling downwards from the sky, towards the player.

These cubes are spinning at random speeds on the x, y, and z rotation.

When they are caught by the empty gameobject (let's call it "catcher"), I need to set the falling cube that gets caught rotation to 0.

So, in JavaScript/UnityScript I thought it would simply be: Caughtcube.transform.Rotation.x = 0; ... And the same for the y and z axis.

Thing is, this always gives different results depending on the rotation of the falling cube, because the falling cube's rotation is random. I thought setting these values to 0 would work. It does in the inspector, but I need it done at runtime dynamically in script.

Any help greatly appreciated.

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
1
Best Answer

Answer by OncaLupe · Dec 18, 2015 at 02:50 AM

Rotations are handled in game as what's called a Quaternion. Quaternions have 4 elements (x, y, z, w), however they do not correspond to the 3-axis rotation shown in the inspector (called Euler). Quaternions are used because they avoid gimbol lock, which is where an object gets stuck on one axis, however they are not easily understood by humans. Luckly there are some methods to convert between Quaternions and Euler.

To set an object to a specific 3-axis rotation, use rotation = Quaternion.Euler(x, y, z). Or to easily set to no rotation as you want, there's rotation = Quaterion.identity. Quaternion.identitiy is a constant for no rotation (equivalent to Quaternion.Euler(Vector3.zero))

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 tperry1x · Dec 18, 2015 at 05:58 PM

Thank you @OncaLupe This worked really well. It turned out I had to use:

 tclone.transform.rotation = Quaternion.Euler(0, 0, 0);
 tclone.transform.localRotation = Quaternion.Euler(0, 0, 0);

and this achieved the effect I was after. Many thanks.

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

34 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

Related Questions

Get angle of rotation around local axis 1 Answer

Rotate camera upward. 0 Answers

Scaling animation that takes rotation into account 0 Answers

move object in a certain direction 0 Answers

Using Local Angles to target enemy object 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