Enemy won't aim at player

So I have a enemy in my scene and everything works, I just cant get it to aim at my player.

The Snowballs are launched out of the launchPoint but I cant figure out how to rotate it to aim directly at the player.

Here’s the code that makes him fire:

void Fire()
{

    if  (!alreadyAttacked)
    {
        GameObject projectile = Instantiate(Snowball, launchPoint.position, launchPoint.rotation);
        Rigidbody rb = projectile.GetComponent<Rigidbody>();
        rb.AddForce(transform.forward * XForce, ForceMode.Impulse);
        rb.AddForce(transform.up * YForce, ForceMode.Impulse);

        alreadyAttacked = true;
        Invoke(nameof(ResetAttack), throwCoolDown);

        Destroy(projectile, 10);
    }
}

He shoots in the general direction of the player, but doesn’t hit him.

Whichever GameObject has the component code you’ve posted above, consider its transform component.

It looks like you’re applying your XForce in the local ‘forward’ direction of that transform, and your YForce in the local ‘up’ direction.

Can’t be certain without more context, but I would guess that you probably want to rotate this transform so that its local ‘forward’ direction is pointing towards the player.

If so, you can do that quite easily. Just work out the vector from your transform to the player’s, then set transform.forward = vectorToPlayer.

If you do that immediately before firing, then your XForce will now be pushing the snowball towards the player.

Hope that helps.