FlamingFire
Official Terrarian
i'm making a custom flamethrower with a custom projetile, and when i scale it down, i realized that the spawn place of the projectile is not in the gun:
but, the hitbox of the projetile spawned on the right place. also, i used custom projetile.
how do i fix this?
gun code :
projetile code :
but, the hitbox of the projetile spawned on the right place. also, i used custom projetile.
how do i fix this?
gun code :
C#:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Terraria.GameContent.Creative;
using Vanniluxe.Content.Projectiles.OnFireFlamethrower
;
namespace Vanniluxe.Content.Items.Ranged.FossilFuel
{
public class FossilFuel : ModItem
{
public override void SetDefaults()
{
// Combat prop
Item.damage = 10; // Gun damage + bullet damage = final damage
Item.DamageType = DamageClass.Ranged;
Item.useTime = 2;
Item.useAnimation = 30;
Item.knockBack = 0.1f; // Gun knockback + bullet knockback = final knockback
Item.autoReuse = true;
Item.reuseDelay = 10;
Item.consumeAmmoOnLastShotOnly = true;
// Visual prop
Item.width = 60;
Item.height = 20;
Item.scale = 1f;
Item.useStyle = ItemUseStyleID.Shoot;
Item.rare = ItemRarityID.Green;
// Other prop
Item.value = 51000;
Item.UseSound = SoundID.Item34;
// Gun prop
Item.noMelee = true;
Item.shoot = ModContent.ProjectileType<OnFireFlamethrower>();; // What kind of projectile the gun fires
Item.shootSpeed = 8f;
Item.useAmmo = AmmoID.Gel; // What ammo gun uses
}
public override bool CanUseItem(Player player)
{
return !player.wet;
}
public override void AddRecipes()
{
Recipe recipe1 = Recipe.Create(ModContent.ItemType<FossilFuel>());
recipe1.AddIngredient(ItemID.FossilOre, 12);
recipe1.AddIngredient(ItemID.Torch, 20);
recipe1.AddRecipeGroup(RecipeGroupID.IronBar, 8);
recipe1.AddTile(TileID.Anvils);
recipe1.Register();
}
public override void SetStaticDefaults()
{
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; // How many items need for research in Journey Mode
}
public override bool CanConsumeAmmo(Item ammo, Player player) => Main.rand.Next(101) <= 20; // Chance in % to not consume ammo
public override Vector2? HoldoutOffset() => new Vector2(-3f, 0f); // Offset editor in pixel
}
}
projetile code :
C#:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameContent;
namespace Vanniluxe.Content.Projectiles.OnFireFlamethrower
{
// This file shows an animated projectile
// This file also shows advanced drawing to center the drawn projectile correctly
public class OnFireFlamethrower : ModProjectile
{
public override void SetStaticDefaults() {
Main.projFrames[Projectile.type] = 7;
}
public override void SetDefaults() {
Projectile.width = 80; // The width of projectile hitbox
Projectile.height = 80; // The height of projectile hitbox
Projectile.scale = 0.1f;
Projectile.friendly = true; // Can the projectile deal damage to enemies?
Projectile.DamageType = DamageClass.Ranged; // Is the projectile shoot by a ranged weapon?
Projectile.ignoreWater = true; // Does the projectile's speed be influenced by water?
Projectile.tileCollide = false; // Can the projectile collide with tiles?
Projectile.penetrate = 2;
Projectile.alpha = 0; // How transparent to draw this projectile. 0 to 255. 255 is completely transparent.
}
public override Color? GetAlpha(Color lightColor) {
return new Color(255, 69, 18, 15) * Projectile.Opacity;
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone){
target.AddBuff(BuffID.OnFire, time: 300);
}
public override void AI() {
Projectile.ai[0] += 1f;
if (Projectile.ai[0] >= 1){
Projectile.rotation += 10;
}
if (Projectile.ai[0] >= 6){
if (Projectile.scale <= 0.8f){
Projectile.scale += 0.03f;
}
}
Projectile.velocity *= 1;
if (++Projectile.frameCounter >=8) {
Projectile.frameCounter = 0;
if (++Projectile.frame >= Main.projFrames[Projectile.type])
Projectile.frame = 0;
}
if (Projectile.ai[0] >= 50f)
Projectile.Kill();
if (Main.netMode != NetmodeID.Server)
{
Dust dust = Dust.NewDustPerfect(
Position: Projectile.Center,
Type: DustID.Torch,
Velocity: Vector2.Zero,
Alpha: 100,
newColor: Color.Orange,
Scale: 0.6f
);
dust.noGravity = true;
dust.fadeIn = -1f;
}
}
}
}