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 /
This question was closed Feb 21, 2015 at 10:22 PM by Myth for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Myth · Jun 08, 2011 at 01:30 AM · axislock

Lock a rotation

Hi,

Is it at all possible to make the rotation of an axis PERMANENTLY zero while still being able to have the other two actively rotating?

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

  • Sort: 
avatar image
2
Best Answer

Answer by Dreamer · Jun 08, 2011 at 01:41 AM

You can lock the rotation of 1 axis by:

 function Update(){
  
 
   //end of script
   transform.eulerAngles.x=0;
 }
Comment
Add comment · Show 4 · 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 rajat · Aug 07, 2013 at 09:09 AM 5
Share

transform.eulerAngles.x=0; This is wrong, you can't modify just one angle, you have to modify the whole object. transform.eulerAngles=new Vector3(0,transform.eulerAngles.y,transform.eulerAngles.z);

avatar image rct3fan24 · Aug 27, 2014 at 04:43 AM 0
Share

@rajat No, I'm pretty sure putting ".x" at the end will allow you to edit just one axis. Adding all that stuff is just unnecessary fluff.

avatar image umbersage · Feb 21, 2015 at 09:54 PM 0
Share

Negative @rct3fan24 That causes the following error:

 error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.eulerAngles'. Consider storing the value in a temporary variable

in Unity and

 Error    1    Cannot modify the return value of 'UnityEngine.Transform.eulerAngles' because it is not a variable

in Visual Studio.

@rajat is correct.

avatar image GameDevGary · Jul 23, 2015 at 07:46 AM 1
Share

For future posterity, in UnityScript, you can edit a single axis by saying

  transform.eulerAngles.x = 0;

However, in C#, you have to assign/store the value in a Vector3, such as

 Vector3 blah = new Vector3
 (transform.eulerAngles.x,
  transform.eulerAngles.y,
  transform.eulerAngles.z);

Why? I don't know. I also don't know why everyone assumes that everybody programs in C#.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Look At while locked in a position 1 Answer

Creating a multiple part turret what locks onto certain axis. 4 Answers

How to lock the y axis in camera script? 2 Answers

How can i prevent the camera from goin down the y axis (othographic Doodle jump camera) 1 Answer

Move player along mesh 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