- Home /
Why does my rotation lock?
I have a script that is taking the electrons of an atom, and rotating them around the ElectronCenter (where the script is put). The electrons are just children of the ElectronCenter and the ElectronCenter is an empty gameobject. But whenever my rotation.eulerangles.x reach 90.0, it just stops. Does anybody know why? The end result is an atom, so if you think you have a beter idea of how to rotate the electrons, go ahead and share. Thanks!
#pragma strict
var rotationSpeed : float = 5.0;
function Start () {
}
function Update () {
transform.rotation.eulerAngles.x += rotationSpeed;
transform.rotation.eulerAngles.y += rotationSpeed;
transform.rotation.eulerAngles.z += rotationSpeed;
}
http://unitygems.com/basic-ai-space-shooter/#Spin
Just replace the space ship with your electrons.
Answer by robertbu · Feb 19, 2014 at 05:47 AM
Try this:
#pragma strict
var rotationSpeed : float = 150.0;
function Update () {
var angle = rotationSpeed * Time.deltaTime;
transform.Rotate(angle, angle, angle);
}
Note you might want to take a look at Transform.RotateAround(). It would allow you to make your electrons orbit without using an empty game object.
Answer by Talmore · Feb 19, 2014 at 05:38 AM
sound like you are having a gimble lock. You may need to create a parent for one or more of your axis. Check out this video: gimble lock explained
Note an alternate possibility to Gimble Lock is that Unity changes the representation of eulerAngles. That is there are multiple eulerAngle representations for any given physical representation, and Unity will change that representation. It can mess up code that reads from eulerAngles like this code does.
Your answer
Follow this Question
Related Questions
Smooth rotation in 90° increments 0 Answers
Euler Angle problem in If check 1 Answer
Store initial rotation in JavaScript 2 Answers
Saving Runtime Changes (JS) 1 Answer
transform.rotation.z gives different value than expected 1 Answer