Hello! I am currently having a problem with a minion shooting a projectile. My minion Dunkleostasis(BonyFish in the code files) is planned to shoot out bones in all directions when it hits an NPC. So because I put a chunk of code intended for Shoot() into OnHitNPC() I had to define a lot of floats manually.
When I tested it out only one bone flies out of the minion. I do not know if this is a problem with me defining all of my floats manually or if I am missing something. Here is the part of the code that I am having problems with.
Thank You so much!
When I tested it out only one bone flies out of the minion. I do not know if this is a problem with me defining all of my floats manually or if I am missing something. Here is the part of the code that I am having problems with.
C#:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
if (Main.myPlayer == projectile.owner)
{
Vector2 targetPos = projectile.position;
Vector2 shootVel = targetPos - projectile.Center;
projectile.netUpdate = true;
Player player = Main.player[projectile.owner];
float speedX = projectile.velocity.X;
float speedY = projectile.velocity.Y;
float numberProjectiles = 8; // 3 shots
float rotation = MathHelper.ToRadians(180);//Shoots them in a 45 degree radius. (This is technically 90 degrees because it's 45 degrees up from your cursor and 45 degrees down)
targetPos += Vector2.Normalize(new Vector2(speedX, speedY)) * 180f; //45 should equal whatever number you had on the previous line
for (int i = 0; i < numberProjectiles; i++)
{
Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))) * .2f; // Vector for spread. Watch out for dividing by 0 if there is only 1 projectile.
Projectile.NewProjectile(projectile.Center, Vector2.Normalize(shootVel) * 15f, ProjectileType<BonyFishBone>(), projectile.damage, projectile.knockBack, Main.myPlayer, 0f, 0f); //Creates a new projectile with our new vector for spread.
}
}
}