Here is my AI code
void AiRotateTowardsGlove ()
{
_enemyPos = Camera.main.WorldToScreenPoint (this.transform.position);
if (GameManager.Instance.gloveSpawned == true)
{
if (_destReached)
{
//Find glove and rotate towards that point
_destReached = false;//until it reaches the PU
_glovePos = Camera.main.WorldToScreenPoint (GameManager.Instance.glove.transform.position);
_relativePos = _glovePos - _enemyPos;
_angle = Mathf.Atan2 (_relativePos.y, _relativePos.x) * Mathf.Rad2Deg;
this.transform.rotation = Quaternion.Euler (new Vector3 (0, 0, (_angle - 90)));
}
This code is working fine but its rotating my enemy by snapping, but I want a smooth rotation instead.
I think I need to update its position in Update function till it reaches its derived roatation and then stop its rotation.
This is slightly tricky also because the enemy is constantly moving forward.
My questions
1. How to do a smooth rotation in z axis alone and
2. How do I make the enemy stop rotating once it knows that it is facing towards the glove so that it can continue to move forward and pick up the glove.
Thanks in advance
↧