- Home /
'Clear' a Coroutine?
Hi, all!
Running a rotation script in a coroutine. It saves the rotation of an object at the beginning, then loops through some leaping code, then snaps the rotation to the previous rotation plus desired degrees for good measure.
This always works the first time.
After that, on the snapping step, my object rotates to the orientation it was in after the first trial. My theory is that the coroutine is somehow holding on to the local variables that are set before the loop, and not 'clearing' them even when StopCoroutine() is called.
Am I doing something wrong here? Feel free to ask for example code if I am being unclear.
Cheers! - YA
Could you post your code? will be able to get a better idea of whats going on.
Answer by Owen-Reynolds · Mar 14, 2015 at 03:36 AM
I'm pretty sure locals in coroutines work just like regular locals. Print it and see. Think it's just bad code somewhere.
I am seeing firstRot.x
on line 23, which is the unknowable quaternion value which should never be used (missing eulerAngles.) But I think, instead of even eulerangles, transform.rotation*Quaternion.Euler(0,0,degrees);
is nicer.
But that error should make it wrong all the time, even the first time.
I stand corrected. It seems the issue did lie in me getting mixed up in my Quaternions vs Eulers. This is odd to me because the code worked almost completely as expected. I thank you for pointing out this issue and will put up the finished code.