Hey! I'm working on putting in movement patterns in our game, and we want the animated sprites to look at the position it's going to while moving. This is my code so far (where m_NextNode.m_Position is the Vector3 the animated sprite is heading towards):
Quaternion rotation = Quaternion.LookRotation((m_NextNode.m_Position - transform.position).normalized, transform.up);
Vector3 tempRot = rotation.eulerAngles;
tempRot.y -= 90f;
tempRot.z *= -1f;
transform.rotation = Quaternion.Euler(tempRot);
This works pretty OK at certain angles, though at some angles the sprite turns upside down or gets another strange rotation (this happens mostly between vectors with big differences on the y-axis). I'm wondering if you could help me out with the rotation. Is there any rotation function in 2D Toolkit you should use? Do I need to flip the animations in some way (however I haven't had any problem with animated sprites changing 'direction' on the x-axis so far)?