transform.rotation gets stuck at 90 degrees. box collider is off and nothing should be touching to create a problem.Imgur: The magic of the Internet
Maybe you can try with quaterions instead of Euler
//pseudocode
Quaternion deltaRotation = Quaternion.AngleAxis(1f, Vector3.right);
rObj.transform.rotation = r.obj.transform.rotation*deltaRotation;
//in single line rObj.transform.rotation *= Quaterion.AngleAxis(1f, Vector3.right)
I think you are facing Gimbal Lock, so quaterions should do the trick
robj.transform.rotation *= Quaternion.AngleAxis(0.1f, rotationVector.x); //=> Wrong. AngleAxis second argument is an axis, i.e., a vector. In your case, I guess is Vector3.Right
It’s pseudo code
This is real code, and the result
using UnityEngine;
public class QuaternionRotation : MonoBehaviour
{
// Update is called once per frame
void Update()
{
Quaternion deltaRotation = Quaternion.AngleAxis(1f, Vector3.right);
this.transform.rotation *=deltaRotation;
}
}
thank you very much! it’s working now. one more question (the last), if you would like to help me… why is this happening when i play and what can i do to prevent it? i want my rubik cube to rotate smoothly and keep the distance between the little cubes. thank you! https://imgur.com/bLKMoqU
Not sure about your problem
Try with Update instead of FixedUpdated and use Time.deltaTime to make it independent from the frame rate.
using UnityEngine;
public class QuaternionRotation : MonoBehaviour
{
public float degreesPerSecond = 1f;
// Update is called once per frame
void Update()
{
Quaternion deltaRotation = Quaternion.AngleAxis(degreesPerSecond*Time.deltaTime, Vector3.right);
this.transform.rotation *=deltaRotation;
}
}
Apply the rotation to a root gameobject and parent the small cubes to that root, but do not rotate the small cubes
thank you, but your solution did not work. i figured it myself what the problem was.
so: the script found a cube with the tag R and added a force to its rotation, then the script found another cube with the tag R and added a force to their rotation (cube1 and cube2). thank you!