Eldrazi
Eater of Worlds
There's a lot of code required for that. I'd suggest you look up the vanilla code for the Chlorophyte bullet and see if you can get a comprehension of it. If not, just change all 'this' and 'base' refs to 'projectile'.how do i make bullets home like the Chlorophyte Bullet
Code:
else if (this.type == 207)
{
if (this.alpha < 170)
{
for (int num136 = 0; num136 < 10; num136++)
{
float x2 = this.position.X - this.velocity.X / 10f * (float)num136;
float y2 = this.position.Y - this.velocity.Y / 10f * (float)num136;
int num137 = Dust.NewDust(new Vector2(x2, y2), 1, 1, 75, 0f, 0f, 0, default(Color), 1f);
Main.dust[num137].alpha = this.alpha;
Main.dust[num137].position.X = x2;
Main.dust[num137].position.Y = y2;
Main.dust[num137].velocity *= 0f;
Main.dust[num137].noGravity = true;
}
}
float num138 = (float)Math.Sqrt((double)(this.velocity.X * this.velocity.X + this.velocity.Y * this.velocity.Y));
float num139 = this.localAI[0];
if (num139 == 0f)
{
this.localAI[0] = num138;
num139 = num138;
}
if (this.alpha > 0)
{
this.alpha -= 25;
}
if (this.alpha < 0)
{
this.alpha = 0;
}
float num140 = this.position.X;
float num141 = this.position.Y;
float num142 = 300f;
bool flag4 = false;
int num143 = 0;
if (this.ai[1] == 0f)
{
for (int num144 = 0; num144 < 200; num144++)
{
if (Main.npc[num144].CanBeChasedBy(this, false) && (this.ai[1] == 0f || this.ai[1] == (float)(num144 + 1)))
{
float num145 = Main.npc[num144].position.X + (float)(Main.npc[num144].width / 2);
float num146 = Main.npc[num144].position.Y + (float)(Main.npc[num144].height / 2);
float num147 = Math.Abs(this.position.X + (float)(this.width / 2) - num145) + Math.Abs(this.position.Y + (float)(this.height / 2) - num146);
if (num147 < num142 && Collision.CanHit(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)(this.height / 2)), 1, 1, Main.npc[num144].position, Main.npc[num144].width, Main.npc[num144].height))
{
num142 = num147;
num140 = num145;
num141 = num146;
flag4 = true;
num143 = num144;
}
}
}
if (flag4)
{
this.ai[1] = (float)(num143 + 1);
}
flag4 = false;
}
if (this.ai[1] > 0f)
{
int num148 = (int)(this.ai[1] - 1f);
if (Main.npc[num148].active && Main.npc[num148].CanBeChasedBy(this, true) && !Main.npc[num148].dontTakeDamage)
{
float num149 = Main.npc[num148].position.X + (float)(Main.npc[num148].width / 2);
float num150 = Main.npc[num148].position.Y + (float)(Main.npc[num148].height / 2);
float num151 = Math.Abs(this.position.X + (float)(this.width / 2) - num149) + Math.Abs(this.position.Y + (float)(this.height / 2) - num150);
if (num151 < 1000f)
{
flag4 = true;
num140 = Main.npc[num148].position.X + (float)(Main.npc[num148].width / 2);
num141 = Main.npc[num148].position.Y + (float)(Main.npc[num148].height / 2);
}
}
else
{
this.ai[1] = 0f;
}
}
if (!this.friendly)
{
flag4 = false;
}
if (flag4)
{
float num152 = num139;
Vector2 vector13 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
float num153 = num140 - vector13.X;
float num154 = num141 - vector13.Y;
float num155 = (float)Math.Sqrt((double)(num153 * num153 + num154 * num154));
num155 = num152 / num155;
num153 *= num155;
num154 *= num155;
int num156 = 8;
this.velocity.X = (this.velocity.X * (float)(num156 - 1) + num153) / (float)num156;
this.velocity.Y = (this.velocity.Y * (float)(num156 - 1) + num154) / (float)num156;
}
}