Код: Выделить всё
if (lookAtMouseEnabled)
{
Lookatmouse();
}
Vector3 mousePos = Input.mousePosition;
//Debug.Log($"Mouse X: {mousePos.x}");
if (mousePos.x >= minXRotation && mousePos.x stoppingDistance)
{
//Rotation
direction.Normalize();
Quaternion lookRotation = Quaternion.LookRotation(direction);
rb.rotation = Quaternion.Slerp(rb.rotation, lookRotation, rotationSpeed * Time.fixedDeltaTime);
//ChasePlayer
Vector3 chasePosition = player.position - player.forward * chaseDistance;
Vector3 newPosition = Vector3.MoveTowards(rb.position, chasePosition, speed * Time.fixedDeltaTime);
rb.MovePosition(newPosition);
// Determine if the player is on the left or right
Vector3 enemyToPlayer = player.position - transform.position;
Vector3 enemyRight = transform.right;
float dotProduct = Vector3.Dot(enemyToPlayer, enemyRight);
if (dotProduct < 0)
{
Debug.Log("Player is on the left.");
}
else
{
Debug.Log("Player is on the right.");
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... -at-player