- Home /
Enemy circling around the player when using LookAt
I read the documentation carefully and the only thing this method should do is to rotate object so it faces the targets current position. Here is the method:
void CheckShoting()
{
if (Mathf.Abs(transform.position.x-playerPosition.position.x) <= range)
{
transform.LookAt(playerPosition);
RaycastHit hit;
if (Physics.Linecast(transform.position, playerPosition.position, out hit))
if (hit.transform.tag == "Player" && haveBullet)
{
Shoot();
haveBullet = false;
}
}
}
Method Shoot doesn't affect the object transform at all. I'm not trying to change objects position, just its rotation.
Answer by ADiSiN · May 07, 2020 at 02:56 PM
Hi!
Since I am not sure how are you implementing enemy movement I could only suggest that the issue could be with their local axises. Imagine you are using transform.forward to move your GameObject, but when you are rotating your GameObject the axis forward is now pointing towards LookAt direction therefore they are cannot move away from player. However, it depends on your movement implementation and I would suggest to re-check it.
Also if you have specific implementation of enemy behaviour when they locked on player I would suggest look up there also, simply by commenting out that section and check if movement working without it would give you a hint.
Your answer
![](https://koobas.hobune.stream/wayback/20220612233419im_/https://answers.unity.com/themes/thub/images/avi.jpg)