Instantiate a projectile facing a Vector3 position in C#

Hello Unity community.

I have a script that allows a turret to look and shoot a target, but not to its current position, to an intercept position so that the turret will hit the target if the target doesn’t change its speed and direction, but my problem is that I don’t know how to instantiate the projectile to face this Vector3 position. Any ideas?

PD: The projectile script allows projectiles to go forward with x speed, and it doesn’t use gravity.

Thanks.

Quaternion.LookRotation gives you a rotation that looks in a certain direction:

Quaternion.LookRotation(new Vector3(0, 1, 0)); //rotation that looks straight up

To get a vector that points from point a to point b, do b - a:

Vector3 a = new Vector3(1, 1, 1);
Vector3 b = new Vector3(5, 1, 1);
Vector3 aTob = b - a; // gives (4, 0, 0);

Combine those to get the correct instantiation:

Vector3 spawnPoint = turret.transform.position;
Vector3 targetPoint = target.transform.position;

Vector3 toTarget = targetPoint - spawnPoint;

Instantiate(bulletPrefab, spawnPoint, Quaternion.LookRotation(toTarget));

Good luck!