I am creating an enemy that moves towards the player but without precision. I though rotatetowards would work for this but with this script, the rotation always defaults to -180 and doesnt change. I’m not sure if Rotatetowards is the wrong thing to use, or if plugging the float “lookangle” directly into lookrot.z is incorrect
void Update()
{
player = GameObject.FindGameObjectWithTag("Player");
targetTimer -= Time.deltaTime;
if(targetTimer <= 0)
{
targetPos = player.transform.position;
targetTimer = maxTargetTimer;
}
lookDirection = targetPos - transform.position;
lookAngle = Mathf.Atan2(lookDirection.y, lookDirection.x) * Mathf.Rad2Deg;
lookRot.z = lookAngle;
transform.Translate(Vector3.right * speed * Time.deltaTime);
transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRot, maxTurn * Time.deltaTime);
}