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 Navigatron · Jun 20, 2013 at 02:49 AM · rotationaxisfreezelockfix

Freeze an Axis Rotation Help?

Scene contains flat terrain, and a cube.
I can fly the cube around! (yay)
The cube is realy hard to fly around, unless the Y axis is locked. (Otherwise the cube can turn backwards, and the controls get all crazy!)
So far, Every method of locking the Y axis has had a problem in it.
If you guys can think of another method, that would be fantastic!

Note: Every axis is a Local axis to the Cube.

Heres what I've tried:

Locking Y rotation in the Rigidbody Constraints section
This, strangely, does absolutely nothing.

transform.eulerAngles.y = 0;
This Works, however the cube Cannot go upside-down, and gets stuck at exactly half way

rigidbody.rotation.y = 0.0;
This is the closest I've come to success. Everything in the air works perfectly, however, The cube gets stuck in the ground whenever i touch it, and is no longer under my control.

Thanks for Reading this! Heres some code:

 #pragma strict
 public var Enginepower : float;
 public var TiltPower : float;
 public var EnginePlate : GameObject;
 public var Particles : GameObject;
 function Start () {
 EnginePlate = GameObject.Find("EngineOn");
 Particles = GameObject.Find("Particles");
 }
 
 function Update () {
     
     
     //******************************************************************************BEGIN PROBLEM CODE AREA *************************************************************************************
     
     
     
     //Several lines, Each of which attempt to Lock Y axis Rotation
     //transform.eulerAngles.y = 0;
     rigidbody.rotation.y = 0.0;
 
 
 
     //*******************************************************************************END PROBLEM CODE AREA **************************************************************************************
     
     
     //Fire the Main Engine Code Block
     if(Input.GetButton("Engine1")){
         //Add virticle force along the local Y axis
         rigidbody.AddRelativeForce(Vector3.up * Time.smoothDeltaTime * Enginepower);
         //Activates Rendering of the Engine plate and Particle Effect
         if(!EnginePlate.renderer.enabled){
             EnginePlate.renderer.enabled = true;
             Particles.renderer.enabled = true;
         }
     }else{
         //Hides engine plate and Particles if engine not on
         if(EnginePlate.renderer.enabled){
             EnginePlate.renderer.enabled = false;
             Particles.renderer.enabled = false;
         }
     }
     
     
     
     if(Input.GetButton("BackwardsTilt")){
         rigidbody.AddRelativeTorque(-Vector3.right * Time.deltaTime * TiltPower);
     }
     
     if(Input.GetButton("ForwardsTilt")){
         rigidbody.AddRelativeTorque(Vector3.right * Time.deltaTime * TiltPower);
     }
     
     if(Input.GetButton("LeftTilt")){
         rigidbody.AddRelativeTorque(Vector3.forward * Time.deltaTime * TiltPower);
     }
     
     if(Input.GetButton("RightTilt")){
         rigidbody.AddRelativeTorque(-Vector3.forward * Time.deltaTime * TiltPower);
     }
 }
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 Slobdell · Jun 21, 2013 at 02:00 AM 0
Share

What is the goal, how do you want it to work? Have you considered fixing the camera behind the cube so that the controls are aleays the same even if it rotates?

avatar image Navigatron · Jun 22, 2013 at 03:12 PM 0
Share

Fixing the camera behind the cube works, but the game looks very odd. All i want is for the cubes Y axis to not rotate, so that the front face faces front. Otherwise, (if the cube rotates after something like a ground collision,) You could push the Rotate away from button and the cube would roll sideways. Thanks for your Reply!

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

Lock Z Rotation. Character Controller. 1 Answer

fixing rotation on a specific axis 1 Answer

Lock the Camera's Y Rotation Axis? 0 Answers

Input axes freeze from opposite input rather than cancel out! 1 Answer

how to lock the z axis rotation 2 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