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 Sel3a · Jun 06, 2015 at 05:30 AM · physicsrigidbodyrotatetransform.rotation

gameobject still rotating over z axis

Hi guys, sorry for my english. i'm realy stack. i'm new with unity and physics. in my project i want to rotate gameobject over z axis when it pass 0.1 angle. The problem is that the gameobject still rotating even after reseting it rotation. One more question, i don't understand why i can't rotated the gameobject after reseting rotation (this code work one time before reseting rotation) and this is my code.

 void FixedUpdate()
 {

     if (this.gameObject.transform.rotation.z > 0.1 || this.gameObject.transform.rotation.z < -0.1) {
         
         if (this.GetComponent<Rigidbody> ().constraints == RigidbodyConstraints.None) {
             this.GetComponent<Rigidbody> ().constraints = RigidbodyConstraints.FreezeRotationZ;
         }
     }
         if (myInput > 0.5) {
             Debug.Log("Rotate left");
             rotateLeft ();
             
         } else if (myInput < -0.5) {
             Debug.Log ("Rotate right");
             rotateRight ();
         }

             else {
                 if (this.gameObject.GetComponent<Rigidbody> ().constraints != RigidbodyConstraints.None) {
                     if(this.gameObject.transform.rotation.z == 0)
                         this.gameObject.GetComponent<Rigidbody> ().constraints = RigidbodyConstraints.None;
                     if (this.gameObject.transform.rotation.z != 0)
                         this.gameObject.transform.rotation = new Quaternion (transform.rotation.x, transform.rotation.y, 0, transform.rotation.w);
                 
     }
             }
 }
 
 void rotateLeft()
 {
     if (this.gameObject.transform.rotation.z > /*amount of degrees*/ 0.4f)
         return;
     //rotate more
     transform.rotation = Quaternion.Slerp(transform.rotation, new Quaternion(transform.rotation.x,transform.rotation.y,0.4f,transform.rotation.w), Time.deltaTime*50f);
     Debug.Log("0.4f atteind");
 }
 void rotateRight()
 {

     if (this.gameObject.transform.rotation.z <  -0.4f) {    
         return;
     }
     //rotate more
     transform.rotation = Quaternion.Slerp(transform.rotation, new Quaternion(transform.rotation.x,transform.rotation.y,-0.4f,transform.rotation.w), Time.deltaTime*50f);
     Debug.Log("-0.4f atteind");
 }

is the problem of rigidbody or what? and for the best parctice do i use transform.rotate and transform.rotation or rotate the gameobject with rigidbody. thanks

Comment
Add comment · Show 3
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 Mouton · Jun 06, 2015 at 06:09 AM 0
Share

The script is working fine, there are no extra rotation. Are you sure there are no other script disturbing ?

avatar image Sel3a · Jun 06, 2015 at 01:38 PM 0
Share

hi. my gameobject is a car and i'm using edy's vehicle for physics. i don't know if there are other script disturbing, as i said i'm new with unity and physics

avatar image Mouton · Jun 06, 2015 at 02:43 PM 0
Share

Well, if you use a pluggin and try to act on a GameObject tied to a script, there may be some conflicts.

Be sure to look Edy's vehicle documentation to gather all the necessary informations for the purpose of your needs. Then, go step-by-step in order to catch where your script miss.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

add force to rotation 1 Answer

How to rotate around with Rigidbody and respect physics? 0 Answers

Gravity only rigidbody 1 Answer

Rigidbodies misbehaving when another is rotated 0 Answers

How to rotate a rigidbody without its attached anchor rigid body flying off? 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