So, I'm trying to manually rotate a bone inside Unity. The bone need to follow the player's position.
So, I'm going to paste a summay of my code (not the code itself, it has too many dependencies)
private SkeletonAnimation skeletonAnimation;
private Bone antenna;
void Start()
{
skeletonAnimation = GetComponent<SkeletonAnimation>();
skeletonAnimation.UpdateBones = UpdateBones;
antenna = skeletonAnimation.skeleton.FindBone("antenna");
}
private void UpdateBones(SkeletonAnimation skeleton)
{
float antennaY = transform.position.y + antenna.WorldY;
float antennaX = transform.position.x + antenna.WorldX;
float distY = GetPlayerPosition().y - antennaY;
float distX = GetPlayerPosition().x - antennaX;
float angle = Mathf.Atan2(distY, distX) * Mathf.Rad2Deg;
antenna.Rotation = angle - antenna.Parent.WorldRotation;
}
So, the code WORKS. But, as soons as it enters a new spine keyframe, and the UpdateBones method takes effect, there is ONE fast frame that the bone is not rotated to the correct position.
I updated my Ant Enemy with a red line texture directly into it's antenna, to see the flickering better.

Oh yeah. I'm using a STEPPED curve in ALL keyframes (to match the game style). But still, the same problem occurs with interpolated keyframes, but it is very hard to see, given the smoothness of the animation.
Is there a way to fix this? I have to call some method just before the antenna.Rotation property is set?
Thanks.