Instantiate Projectile towards player (regardless of transform.rotation)

I have an enemy in my game who (as you’d expect) shoots at me if I’m in range. I have a gun attached to the enemy model, and a script which instantiates a projectile at the end of it(using a bulletSpawn empty GameObject). The problem is, as part of the shooting animation the gun isn’t facing directly at me.

How can I instantiate the bullet in the direction of the player?

Thanks

You substract the position of the bullet from the position of the player.
That should give you a vector in the direction the bullet should take.

Normalize it then multiply it by the speed you want and you have your vector for the velocity of the bullet.

var direction = enemy.transform.position - projectileStartPosition;
var projectile = (Transform)Instantiate(projectilePrefab, projectileStartPosition, Quaternion.LookRotation(direction));

Or, alternatively, you can call

projectile.LookAt(enemy.transform);

just after instantiating.