tModLoader Need help[homing projectile]

Cleyera

Steampunker
I want shoot projectiles along the yellow vector but they go along the blue vector.
So they target and hit inside of blue circle.They can chase but I want to them to target NPCs center(inside of yellow circle).
8Eb0QOu

https://imgur.com/a/8Eb0QOu

I read many thread and try.I could not fix this.
How can I fix this?Please tell me how to fix this.

There is this AI part...
Code:
public override void AI()
        {
            int num3 = projectile.frameCounter;
            if (Main.rand.NextBool(3))
            {
                Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 6, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f);
            }
            projectile.frameCounter = num3 + 1;
            if (projectile.frameCounter > 0)
            {
                num3 = projectile.frame;
                projectile.frame = num3 + 1;
                projectile.frameCounter = 0;
                if (projectile.frame > 2)
                {
                    projectile.frame = 0;
                }
            }
            if (projectile.velocity.X < 0f)
            {
                projectile.spriteDirection = -1;
                projectile.rotation = (float)Math.Atan2(-(double)projectile.velocity.Y, -(double)projectile.velocity.X);
            }
            else
            {
                projectile.spriteDirection = 1;
                projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X);
            }
            if (projectile.ai[0] >= 0f && projectile.ai[0] < 200f)
            {
                int num543 = (int)projectile.ai[0];
                NPC nPC2 = Main.npc[num543];
                if (nPC2.CanBeChasedBy(projectile, false))
                {
                    float num544 = 20f;
                    Vector2 vector40 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
                    float num545 = Main.npc[num543].position.X - vector40.X;
                    float num546 = Main.npc[num543].position.Y - vector40.Y;
                    float num547 = (float)Math.Sqrt((double)(num545 * num545 + num546 * num546));
                    num547 = num544 / num547;
                    num545 *= num547;
                    num546 *= num547;
                    projectile.velocity.X = (projectile.velocity.X * 14f + num545) / 15f;
                    projectile.velocity.Y = (projectile.velocity.Y * 14f + num546) / 15f;
                }
                else
                {
                    float num548 = 1000f;
                    for (int num549 = 0; num549 < 200; num549++)
                    {
                        if (Main.npc[num549].CanBeChasedBy(projectile, false))
                        {
                            float num550 = Main.npc[num549].position.X + (float)(Main.npc[num549].width / 2);
                            float num551 = Main.npc[num549].position.Y + (float)(Main.npc[num549].height / 2);
                            float num552 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num550) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num551);
                            if (num552 < num548 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num549].position, Main.npc[num549].width, Main.npc[num549].height))
                            {
                                num548 = num552;
                                projectile.ai[0] = (float)num549;
                            }
                        }
                    }
                }
                return;
            }
            projectile.Kill();
            return;
        }

And I'm not good at English.Sorry...
 
Back
Top Bottom