How to change bullet colour?

pop12601

Terrarian
Hey everyone! So I'm new to modding terraria, and I'd like to be able to create a new upgraded version of the paintball gun. Well, so far I got everything working fine. But the only issue is when I shoot it in game, the colour of the paintballs shot are only a dark red, and I would like it to have a small variety, just like the paintball gun.
Any help would be appreciated, thanks in advance!
 
Hey everyone! So I'm new to modding terraria, and I'd like to be able to create a new upgraded version of the paintball gun. Well, so far I got everything working fine. But the only issue is when I shoot it in game, the colour of the paintballs shot are only a dark red, and I would like it to have a small variety, just like the paintball gun.
Any help would be appreciated, thanks in advance!
Are you using a custom sprite? If so, could you show us? If not (and you're using the vanilla paintball projectile), have you tried taking a look at how they're handled in vanilla code?
 
Hey everyone! So I'm new to modding terraria, and I'd like to be able to create a new upgraded version of the paintball gun. Well, so far I got everything working fine. But the only issue is when I shoot it in game, the colour of the paintballs shot are only a dark red, and I would like it to have a small variety, just like the paintball gun.
Any help would be appreciated, thanks in advance!
Nope, I'm sticking with the normal paintball sprite. I just took a look at the vanilla code, and it doesn't seem to have anything to change the colour of it.
 
Nope, I'm sticking with the normal paintball sprite. I just took a look at the vanilla code, and it doesn't seem to have anything to change the colour of it.
Let me get this straight: You're using the same sprite as the normal paintball bullet, but different code?
 
Let me get this straight: You're using the same sprite as the normal paintball bullet, but different code?
Yes, I'm using pretty much the same code as the example gun in the examplemod, but I changed the this.shoot line to match with the paintball projectile.
 
Yes, I'm using pretty much the same code as the example gun in the examplemod, but I changed the this.shoot line to match with the paintball projectile.
Allright, so you're overriding the shoot function I take it? If not, you want to do that.
Spawn the projectile like you normally would, but change the last parameter (ai1) to the following:
Code:
Main.rand.Next(12) / 6
So the full line would be something like:
Code:
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0, Main.rand.Next(12) / 6);
That last bit is used inside the Paintball projectile to determine its color.
 
Allright, so you're overriding the shoot function I take it? If not, you want to do that.
Spawn the projectile like you normally would, but change the last parameter (ai1) to the following:
Code:
Main.rand.Next(12) / 6
So the full line would be something like:
Code:
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0, Main.rand.Next(12) / 6);
That last bit is used inside the Paintball projectile to determine its color.
Hmm, well I got the code in, but it seems what that does is just make some paintballs black rather than red.
Do you mind telling me what those last 2 parameters do exactly, because I've been fiddling with values a little and not much has been changing...
 
Hmm, well I got the code in, but it seems what that does is just make some paintballs black rather than red.
Do you mind telling me what those last 2 parameters do exactly, because I've been fiddling with values a little and not much has been changing...
Allright, so those last two values when you spawn a projectile are its ai values.
The Paintball projectile uses the second ai value (the one we're assigning here via the NewProjectile method) to determine its color, or rather the color of the dust/particles it spawns. This ai value I keep talking about is used like follows in the vanilla code for the Paintballs:
Code:
Color newColor = Main.hslToRgb(this.ai[1], 1f, 0.5f);
After which a Dust is spawned with this color (this refers to the projectile). The method hslToRgb takes 3 parameters: hslToRgb(Hue, Saturation, Luminosity). As you can see, ai[1] is modifying the Hue of the color, which is what we want.

I'm not sure why the projectile would act differently for you than it does for vanilla, because everything is basically set the same.
 
Back
Top Bottom