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
1
Question by alexanderameye · Jan 04, 2015 at 02:27 PM · rotationeuleranglesresetrotations0

Set rotation values equal to 0

I have an object that's rotated around the y-axis (let's say 0,30,0). Is there any way I can set these values equal to 0? So I don't want to rotate the object back to 0,0,0, but I want to set the rotation at 0,30,0 as a default rotation.

So in the script I want to set that the rotation values are now equal to 0,0,0 without changing the rotation/scale or position of the object.

Thank you very much!!!

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

5 Replies

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

Answer by _dns_ · Jan 04, 2015 at 04:03 PM

Hi, as far as I understand: you want to rotate your object without rotating the transform component. That is, only rotate the mesh (I assume that object contains a mesh). I see 3 options:

  • modify the mesh before importing it: any 3D editing software will do this

  • modify the mesh itself by a script

  • Insert a new Transform as the parent of this object

Option 3 should be the quickest way to do it: create an object containing only the mesh as a child of the main object. Change the rotation of this child mesh to (0,30,0). The parent object still have 0 rotation and can contain all the scripts you need, be referenced by other object etc...

Option 2 would take place in the Start() of the object. You could get the vertices of the mesh using the MeshFilter component and rotate them. Create a Matrix4x4 from a TRS with only a (0,30,0) rotation. Use it to rotate the vertices by multiplying the vertices positions by the matrix, and set the vertices back to the mesh. You should then recompute the normals and the bounds (or rotate the normals with the matrix). Your script should be close to this one.

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 alexanderameye · Jan 04, 2015 at 04:30 PM 0
Share

Just to make sure that you understand what I mean, this is what I would like to have:

An object with rotation 0,30,0 When I click play, the script sets the rotation values to 0,0,0 but the object stays, it doesn't move or rotate When I tranform the rotation in the script to 0,30,0, the object rotates with 30 degrees from it's initial position (so this would be 0,60,0 if I didn't set the values to zero)

Thank you for your time and effort!

$$anonymous$$

avatar image _dns_ · Jan 04, 2015 at 04:43 PM 1
Share

Ok, that's what I understood :) The thing is when you write "but the object stay" : it makes no sense. The object cannot "stay", it is one with the transform's rotation. That's why object (= transform) hierarchy is convenient.

The option 3 I described is what you want: You have an object O that contains scripts but no mesh. You create an object G that only contains a mesh. You make G the child of O (with G's scale, position & rotation to 0).

Now, consider O's rotation is 0, and G's rotation is 0. Everything is "aligned" = default.

Rotate G by (0,30,0) in the inspector. You now have a rotated object in the scene, but O's rotation is still = to 0. That's your initial values.

Now, in game, if you want to rotate G, don't: rotate O ins$$anonymous$$d. O's rotation will be 0 when you start the game. If you rotate O by (0,30,0) it will rotate G by 30 too, then G will be rotated by 60.

That's what transform hierarchy is made for ;-)

avatar image alexanderameye · Jan 04, 2015 at 04:47 PM 0
Share

Oh I understand I need it for a door opening system, and I have a door object that is child to a hinge. So when I rotate the hinge, the door opens/closes like a door ins$$anonymous$$d of just turning around it's middle axis. I figured out how I can achieve what I want thanks to your answer, tyvm!

avatar image
4

Answer by flaviusxvii · Jan 04, 2015 at 03:05 PM

Add this line to the Start() function..

 transform.rotation = Quaternion.Euler(0, 30, 0);

That will make it start with that rotation.

Comment
Add comment · Show 2 · 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 alexanderameye · Jan 04, 2015 at 03:08 PM 0
Share

yes, I'll try that, but that will put the rotation of the object in the inspector to 0,30,0

I want that the values in the inspector show 0,0,0 but that the object is rotated 30 degrees around the y axis

avatar image LZYGYZ · Mar 24, 2017 at 09:20 AM 0
Share

Thanx thats what i want :)

avatar image
0

Answer by malekbakeer · Jan 04, 2015 at 02:35 PM

 // put the following in where u like
 
 transform.rotation.y = 0;
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 alexanderameye · Jan 04, 2015 at 02:37 PM 0
Share

yes, but won't that rotate the object when the script is running? I want the object to stay in place, but I want the value to change

avatar image
0

Answer by Budlog · Jul 15, 2015 at 07:22 PM

try Space.World as a 4th paremeter of Rotate method.

 transform.Rotate(0, angle * 8, 0,Space.World); 
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 123iamking · Feb 06, 2016 at 02:15 PM

I think you mean: YourGameObject.transform.localRotation = Quaternion.identity;

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 ClearRoseOfWar · Oct 15, 2020 at 08:40 PM 0
Share

Thank you!!! :)

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

32 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

Related Questions

Store initial rotation in JavaScript 2 Answers

Problems caused by non-unique Euler angle solutions 1 Answer

Instantiating an object in front of the player 3 Answers

Camera Zoom from rotation. 0 Answers

how do i set the eular angles of a parent object to the same thing as the child object, without changing the rotation of the child 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