- Home /
Question by
HammockHead · Jun 06, 2014 at 02:47 AM ·
quaternioncuberoll
Roll a cube help
I have written a script to rotate a cube on keypress which looks like this:
function move (v : Vector3) {
isRotating = true;
start = transform.rotation;
v = v.normalized;
n = start * Vector3.Cross(Vector3.up,v);
c = Mathf.Cos(Mathf.PI/4);
s = Mathf.Sin(Mathf.PI/4);
rotate = Quaternion(n.x*s,n.y*s,n.z*s,c);
i = 0.0;
rate = 1.0/rotationRate;
while (i < 1.0){
i += Time.deltaTime * rate;
transform.rotation = Quaternion.Lerp(start, start*rotate, Mathf.SmoothStep(0.0, 1.0, i));
yield;
}
transform.rotation = Quaternion.identity; //dont want to use!!!
isRotating = false;
}
My problem is that I have to resort to a reset of the rotation after call or the angles lose precision and also I start rotating the cube incorrectly. Does anyone have any ideas on how I can fix the code so that it doesn't need the reset.
Comment