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 frogsbo · Jan 21, 2014 at 01:17 PM · rotationspaceship

Spaceship gets stuck at transform.eulerAngles.x =270

I want my spaceship to loop the loop when i press up, to loop 360' , but it climbs to vertical and then it stays stuck upwards at transform.eulerAngles.x =270 and then when i press the buttons it just vibrates in stuck position.

           if(Input.GetKey("w"))//------ NAVIGATION ----------
  { 
           transform.eulerAngles.x += rotspd * Time.deltaTime * 7;
  }             
  
       if(Input.GetKey("s"))
  { 
           transform.eulerAngles.x += -rotspd * Time.deltaTime * 7;
  }        

i added this to prevent it becoming stuck at 270, but i still cant go more than 270', i.e. straight up.

 if(transform.eulerAngles.x==270 )//------ stops it gettign stuck at 270degrees
  { 
            transform.eulerAngles.x=275;
  }    
 
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
2
Best Answer

Answer by HappyMoo · Jan 21, 2014 at 01:35 PM

You can't use EulerAngles like that. Internally, Rotations are stored as Quaternions and there are more than one set of EulerAngles describing the same Quaternion, so what you put into EulerAngles might not stay the same.

A fast fix for your problem would be to keep your angle in a float and only change that float and only write to the eulerAngles, never read from them.

 if(Input.GetKey("w"))
 { 
    rotX += rotspd * Time.deltaTime * 7;
 }        
 if(Input.GetKey("s"))
 { 
    rotX += -rotspd * Time.deltaTime * 7;
 }
 
 transform.eulerAngles = new Vector3(rotX,0,0);

btw, what's doing the 7 there? This should be in rotspd. Multiplay you rotspd by 7.

The above should fix your problem. If you need to rotate around another axis, you may still experience gimbal lock, but that's for another time - maybe read up on "gimbal lock" first... and it may not apply to your situation

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 frogsbo · Jan 21, 2014 at 07:55 PM 0
Share

Thanks! i have learnt that there is gimbal lock in rotations. i was hoping there would be a kind of fix/framework in unity so that a programmer can put in x/y/z angles and an adaptive code translates it to quaternions.

sorry it's messy, it's the first code i wrote after reading tornado twins tutorial 2 years ago. here are the keys i was hoping for, it starts flipping insanely between +90 and -90 every frame, now i added z axis into New Vector3(rotx,roty,euler.z)

there other spaceship codes on unitycommunity.

 if(Input.Get$$anonymous$$ey("w"))//------ NAVIGATION ----------
  { 
           rotX += rotspd * Time.deltaTime ;
  }             
  
       if(Input.Get$$anonymous$$ey("s"))
  { 
           rotX -= rotspd * Time.deltaTime ;
  }        
  
       if(Input.Get$$anonymous$$ey("a"))
 {
           rotY -= rotspd * Time.deltaTime ;
  }        
  
       if(Input.Get$$anonymous$$ey("d"))
  { 
          rotY += rotspd * Time.deltaTime ;
  }    
  transform.eulerAngles = new Vector3(rotX,rotY,transform.eulerAngles.z);
  //Roll craft:
       if(Input.Get$$anonymous$$ey("r"))
 {
           constantForce.relativeTorque.z = 4;;
  }        
  
       if(Input.Get$$anonymous$$ey("f"))
  { 
          constantForce.relativeTorque.z = -4;;
  }             
avatar image HappyMoo · Jan 21, 2014 at 09:10 PM 0
Share

try removing transform.eulerAngles.z. put a 0 and see how it reacts, Other than that, if you don't want any gimbal lock problems, you have to only operate on Quaternions and not on Euler Angles

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

19 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

Related Questions

Artificial Gravity "SpaceShip" 1 Answer

Flip over an object (smooth transition) 3 Answers

Turret. Detect if target is inside horizontal and vertical arcs 2 Answers

2D spaceship rotation 0 Answers

Space Game - Click To Move and Mouse Look 1 Answer


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