Enemy not facing player when enter rotation orbit
I have a player, and enemy which are facing and chasing to the player, when enemy enters their orbit, they stops moving to player and moves by their orbit around the player, if player is not moving all works good, but if player get closer to the enemy, enemy will still moves by orbit but not rotating to player.
void MovementAI()
{
distance = Vector3.Distance(transform.position, playerTransform.transform.position); //GET DISTANCE BETWEEN ENEMY AND PLAYER
Vector3 direction = playerTransform.position - transform.position; //GET DIRECTION TO PLAYER
direction.Normalize(); //FETCH DIRECTION AND SETS LENGTH OF VECTOR3 TO 1.0f
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; //GET PLAYERS ANGLE
rb.rotation = angle; //ROTATE ENEMY
if (distance > maxOrbit) //IF TOO FAR FROM PLAYER
{
movement = direction;
}
else if (distance < minOrbit) //IF TO CLOSE TO PLAYER
{
fireCooldown -= Time.deltaTime; //DOUBLES FIRERATE
movement = -direction;
}
else //IF ON ORBIT
{
transform.RotateAround(playerTransform.transform.position, Vector3.forward, rotationDegree * Time.deltaTime);
}
}
screenshot-2.png
(46.2 kB)
Comment