I’m trying to rotate a cube 90 degrees. My script was working until I started to simplify it
I’ve starred myself blind as to why it’s not working anymore. The cube just rotates a tiny bit and then starts jittering in its rotating movement.
const float ROTATION_SPEED = 4.0f;
Quaternion _sourceRotation;
Quaternion _targetRotation;
void Start () {
_sourceRotation = this.transform.rotation;
_targetRotation = this.transform.rotation;
}
void Update () {
float angle = Quaternion.Angle(this.transform.rotation, _targetRotation);
if (angle < 0.1f) {
_sourceRotation = _targetRotation;
_targetRotation = this.transform.rotation * Quaternion.Euler(90, 0, 0); //a random rotation will be chosen here, but hardcoded right now for simplicity
}
this.transform.rotation = Quaternion.Lerp(_sourceRotation, _targetRotation, Time.deltaTime * ROTATION_SPEED);
}
If I change _sourceRotation to a Transform instead of a Quaternion and store the cubes transform instead or its rotation in _sourceRotation, and in the Quaternion.Lerp use _source.rotation it does the rotation as it should, but I don’t understand why… feeling frustrated
As I just started working with Lerp myself, I don't have a full answer for you, but it might be worth noting that Unity's official video tutorial [here][1] is flawed. Information on why it is flawed: http://www.blueraja.com/blog/404/how-to-use-unity-3ds-linear-interpolation-vector3-lerp-correctly It looks to me like the third argument for Lerp in the last line of your code might be the problem. Again, not sure, but trying to point you in the right direction. [1]: http://unity3d.com/learn/tutorials/modules/beginner/scripting/lerp
– reinfeldxThank you. It was confusing me a bit, since I also seem to recall what hexagonius writes about t [0;1].
– nesdroc