I am quite a noob in Unity and just started learning. I managed to rotate the bullets coming from the enemy to point in the direction of the player. When I try to use the same, slightly changed, code, to manage the variable names, and put it into the “Update” function, it spins continuously.
In the “start” function it works just fine and rotates the enemy to look at the player when the game is started.
This is the code:
public GameObject shooter;
PlayerController target;
Vector2 aimInDirection;
void Update()
{
ShooterAiming();
}
private void ShooterAiming()
{
target = GameObject.FindObjectOfType<PlayerController>();
aimInDirection = (target.transform.position - transform.position).normalized;
shooter.transform.Rotate(0.0f, 0.0f, Mathf.Atan2(aimInDirection.y, aimInDirection.x) * Mathf.Rad2Deg);
}
Hope someone can help me