So I’m working on a game, and here’s a line of code I’m working on:
if (scourgetimer > 0 && pos.x < 6 && pos.x > -4)
{
PointTowards(bship.transform);
PointTowards(bship.gameObject);
scourgetimer -= Time.deltaTime;
}
void PointTowards(GameObject bship) {PointTowards(bship.transform); }
void PointTowards(Transform bship) { PointTowards(bship.position); }
void PointTowards(Vector3 bship)
{
Vector3 difference = bship - transform.position;
transform.rotation = Quaternion.LookRotation(difference.normalized, Vector3.up);
}
Basically, this is meant to make an object find the position of the player character’s gameObject, and point towards it.
However, when I tested the script, the enemy in question just looks in a completely different angle and doesn’t move.
Is there something wrong with how I’m doing this?