Here’s my problem : I’m trying to make an object rotate 90 degree over time (blockController). I made an animation that would do such, placed it on an animation component in an empty object(animatron). Now I figured that by parenting the animatron to the blockController, I could have the animatron rotate it and the blockController, then unparent itself and reset its position.
So far it works. What bugs is afterward, when I try to do the operation again : I assumed that I would just have to parent the blockController under the animatron again and that playing the animation would result in the blockController turning an additional 90 degrees.
What happens is that it follows the coordinate of the animation from start again, meaning it resets its rotation and rotate the original 90 degrees. It’s where my knowledge gets fuzzy and I’m not sure how and why to fix this… I’m quite the beginner so I still feel I might be missing something basic.
Here are the relevant parts of the code:
//Function to wait for animation to finish
IEnumerator waitForAnimation(AnimationClip playingAnim)
{
yield return new WaitForSeconds(playingAnim.length);
blockController.transform.parent = null;
animatron.transform.position = new Vector3(0,0,0);
}
//Place animatron over block position
animatron.transform.position = blockController.transform.position;
//Parent to block, play anim, unparent after anim is played and reset animatron pos and rot
blockController.transform.parent = animatron.transform;
animatron.animation.Play("rotationCwise");
StartCoroutine (waitForAnimation(animatron.animation["rotationCwise"].clip));