Hay there,
i’m making a small 2D Game with a friend of mine. We want to create a tower turning in the players direction. We found this solution, wich is working quite fine for a while but then gets stuck and the tower is not turning anymore.
Sorry for spelling mistakes, i’m not an english native.
void FixedUpdate()
{
if (player != null)
{
TowerRotation(player.transform);
}
}
void TowerRotation(Transform target)
{
Vector3 dir = target.position - shotSpawn[4].transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion lerpTo = Quaternion.AngleAxis(angle, Vector3.forward);
shotSpawn[4].transform.rotation = Quaternion.Lerp(shotSpawn[4].transform.rotation, lerpTo, Time.time * rotSpeed);
}