POCKETS
Terrarian
I figured I would ask in these forums (as well as the tMod Discord) about the code for the Chlorophyte dust trail, and what I'm attempting to do with it.
I have a custom projectile that behaves like the Chlorophyte bullet, in that it homes in on targets, and leaves a dust trail. The code is working fine, and the trail is working fine. However, I am attempting to edit the dust trail so that the trail starts to spawn at a set distance behind the projectile, and not on the projectile itself.
This is the code for the dust trail (TealArrowDust4 is my custom dust)
I believe this code works as follows -
The position of the spawning of the dust is determined by the current position of the projectile. Then, the current velocity of the projectile is subtracted, which makes the dust spawn in a set location (doesn't move or fall to the ground with noGravity set to true). There is some extra math involved so that it can spawn the dust over and over again, but that's basically it.
In order to get the dust to start spawning a set distance behind the projectile, and not at the projectiles current position, I'm going to need to change how the position is calculated, but I'm at a loss when it comes to how. I've tried several things, but I'm still new to C# and coding/modding. I've been thinking about a way to track where the projectile has already been, using that as it's spawn location, but again, I wouldn't know where to start.
Any suggestions or hints would be awesome!
It has been suggested that I use an array to store the projectiles positions, which could work. I understand how simple arrays work, but I think I'd first need to convert the positions (Vectors) into integers, and I'm a bit lost on how to do that.
I have a custom projectile that behaves like the Chlorophyte bullet, in that it homes in on targets, and leaves a dust trail. The code is working fine, and the trail is working fine. However, I am attempting to edit the dust trail so that the trail starts to spawn at a set distance behind the projectile, and not on the projectile itself.
This is the code for the dust trail (TealArrowDust4 is my custom dust)
Code:
for (int num163 = 0; num163 < 10; num163++) // Spawns 10 dust every ai update (I have projectile.extraUpdates = 1; so it may actually be 20 dust per ai update)
{
float x2 = projectile.position.X - projectile.velocity.X / 10f * (float)num163;
float y2 = projectile.position.Y - projectile.velocity.Y / 10f * (float)num163;
int num164 = Dust.NewDust(new Vector2(x2, y2), 1, 1, mod.DustType<TealArrowDust4>(), 0f, 0f, 0, default(Color), 1f);
Main.dust[num164].alpha = projectile.alpha;
Main.dust[num164].position.X = x2;
Main.dust[num164].position.Y = y2;
Main.dust[num164].velocity *= 0f;
Main.dust[num164].noGravity = true;
Main.dust[num164].fadeIn *= 1.8f;
Main.dust[num164].scale = 2f;
}
I believe this code works as follows -
The position of the spawning of the dust is determined by the current position of the projectile. Then, the current velocity of the projectile is subtracted, which makes the dust spawn in a set location (doesn't move or fall to the ground with noGravity set to true). There is some extra math involved so that it can spawn the dust over and over again, but that's basically it.
In order to get the dust to start spawning a set distance behind the projectile, and not at the projectiles current position, I'm going to need to change how the position is calculated, but I'm at a loss when it comes to how. I've tried several things, but I'm still new to C# and coding/modding. I've been thinking about a way to track where the projectile has already been, using that as it's spawn location, but again, I wouldn't know where to start.
Any suggestions or hints would be awesome!
It has been suggested that I use an array to store the projectiles positions, which could work. I understand how simple arrays work, but I think I'd first need to convert the positions (Vectors) into integers, and I'm a bit lost on how to do that.
Last edited: