- Home /
How does the RigidBody.Transform.rotate method work with degrees at 0?
I am very new with Unity Engine and when I was experimenting with the rigid body component I noticed the following:
When I want to rotate a game object with RigidBody.Transform.rotate method one integer by time, if the angle is at 359 degrees and I try to rotate adding one more degree, the position does not end at degree 0, it always includes a decimal value, this also applies if the object is at degree 1 and I try to rotate subtracting one degree. So:
How does the RigidBody.Transform.rotate method work?
This method is suitable for this purpose?
How do I achieve a rotation that can reach the value of absolute 0 for degrees?
The next code is what I am using and it is only a prototype (is expected to be different at the end, adding more functions), its functional behavior is to rotate the object 90° only at axis Y:
     private float pastAngle=-1;
     private float direction;
     public bool rotationProcessIsOn = false;
     public int count = 0;
 
 
     void FixedUpdate ()
     {
         if (Input.anyKey && ! rotationProcessIsOn) {
             rotationProcessIsOn = true;    
             direction = Input.GetAxis("Horizontal") ;
             if (direction < 0) {
                 direction = -1;
             } else if(direction>0){
                 direction = 1;
             }
         }
 
         if (rotationProcessIsOn) {
             Rotate90degrees ();
         }
 
 
     }
         
     void Rotate90degrees ()
     {
         if (GetComponent<Transform> ().rotation.eulerAngles.y != pastAngle) {
             pastAngle=GetComponent<Transform> ().rotation.eulerAngles.y;
             count++;
             GetComponent<Rigidbody> ().transform.Rotate (0, direction, 0);
             if (count == 90) {
                 rotationProcessIsOn = false;
                 count = 0;
             }
         }
     }
If the object is at 270°, and you try to get the position at 0° moving with input axis to right or 90 moving to the left, it will end at 0 with decimal value
Thank you for your attention
Your answer
 
 
             Follow this Question
Related Questions
AddTorque stops working when model is vertical 0 Answers
If angle is greater than 5, do something, if less than -5, do something else [Answered] 2 Answers
Can you add a force to a rigidbody at an angle? 3 Answers
Why can't I assign a rotation to a rigidbody Object? 1 Answer
Rigidbodies won't collide if mass difference is too high 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                