Hewo! I'm kinda new at modding stuff and wanted to add a large shortswords as a giant rapiers. So, I kinda made what I've want but any stuff what can increase the attack speed increasing the hitbox as well. And after this, Rapier hitting the target by air. How could I fix it?
This is normal state and it's hitting on the end of the blade.
This happens if something increasing the attack speed.
Rapier as Item code:
using SomeStuffMod.Content.Projectiles;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria.Localization;
namespace SomeStuffMod.Content.Items.Rapiers
{
public class BlackSteelRapier : ModItem
{
public override void SetDefaults()
{
Item.damage = 145;
Item.width = 50;
Item.height = 50;
Item.useTime = 7;
Item.crit = 26;
Item.useAnimation = 7;
Item.DamageType = DamageClass.MeleeNoSpeed;
Item.useStyle = ItemUseStyleID.Rapier;
Item.knockBack = 7;
Item.value = Item.buyPrice(gold: 10);
Item.rare = ItemRarityID.Gray;
Item.UseSound = SoundID.Item71;
Item.autoReuse = true;
Item.noUseGraphic = true;
Item.noMelee = true;
Item.shoot = ModContent.ProjectileType<BlackSteelRapierProjectile>();
Item.shootSpeed = 9f;
}
public override void AddRecipes()
{
Recipe recipe = Recipe.Create(ModContent.ItemType<Items.Rapiers.BlackSteelRapier>());
recipe.AddIngredient<Items.BlackSteelBar>(10);
recipe.AddIngredient(ItemID.LihzahrdBrick, 5);
recipe.AddTile(TileID.LihzahrdFurnace);
recipe.Register();
}
}
}
Rapier as Projectile code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Enums;
using Terraria.ModLoader;
using System;
using Terraria.ID;
using Microsoft.Xna.Framework.Graphics;
namespace SomeStuffMod.Content.Projectiles
{
public class BlackSteelRapierProjectile : ModProjectile
{
public const int FadeInDuration = 15;
public const int FadeOutDuration = 18;
public const int TotalDuration = 30;
public float CollisionWidth => 10f * Projectile.scale;
public int Timer
{
get => (int)Projectile.ai[0];
set => Projectile.ai[0] = value;
}
public override void SetDefaults()
{
Projectile.Size = new Vector2(42);
Projectile.aiStyle = ProjAIStyleID.ShortSword;
Projectile.friendly = true;
Projectile.penetrate = -1;
Projectile.tileCollide = false;
Projectile.scale = 2.8f;
Projectile.DamageType = DamageClass.Melee;
Projectile.ownerHitCheck = true;
Projectile.extraUpdates = 1;
Projectile.timeLeft = 360;
Projectile.hide = true;
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
target.AddBuff(BuffID.BrokenArmor, 180);
target.AddBuff(BuffID.Weak, 180);
target.AddBuff(BuffID.Ichor, 180);
target.AddBuff(BuffID.Venom, 180);
}
public override void AI()
{
Player player = Main.player[Projectile.owner];
Timer += 1;
if (Timer >= TotalDuration)
{
Projectile.Kill();
return;
}
else
{
player.heldProj = Projectile.whoAmI;
}
Projectile.Opacity = Utils.GetLerpValue(0f, FadeInDuration, Timer, clamped: true) * Utils.GetLerpValue(TotalDuration, TotalDuration - FadeOutDuration, Timer, clamped: true);
Vector2 playerCenter = player.RotatedRelativePoint(player.MountedCenter, reverseRotation: false, addGfxOffY: false);
Projectile.Center = playerCenter + Projectile.velocity * (Timer - 1f);
Projectile.spriteDirection = (Vector2.Dot(Projectile.velocity, Vector2.UnitX) >= 0f).ToDirectionInt();
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2 - MathHelper.PiOver4 * Projectile.spriteDirection;
SetVisualOffsets();
}
private void SetVisualOffsets()
{
const int HalfSpriteWidth = 89 / 2;
const int HalfSpriteHeight = 90 / 2;
int HalfProjWidth = Projectile.width / 2;
int HalfProjHeight = Projectile.height / 2;
DrawOriginOffsetX = 1;
DrawOffsetX = -(HalfSpriteWidth - HalfProjWidth);
DrawOriginOffsetY = -(HalfSpriteHeight - HalfProjHeight);
if (Projectile.spriteDirection == 1)
{
DrawOriginOffsetX = -(HalfProjWidth - HalfSpriteWidth);
DrawOffsetX = (int)-DrawOriginOffsetX * 2;
DrawOriginOffsetY = 0;
}
else
{
DrawOriginOffsetX = (HalfProjWidth - HalfSpriteWidth);
DrawOffsetX = 0;
DrawOriginOffsetY = 0;
}
}
public override bool ShouldUpdatePosition()
{
return false;
}
public override void CutTiles()
{
DelegateMethods.tilecut_0 = TileCuttingContext.AttackProjectile;
Vector2 start = Projectile.Center;
Vector2 end = start + Projectile.velocity.SafeNormalize(-Vector2.UnitY) * 10f;
Utils.PlotTileLine(start, end, CollisionWidth, DelegateMethods.CutTiles);
}
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
{
Vector2 start = Projectile.Center;
Vector2 end = start + Projectile.velocity * 27f;
float collisionPoint = 0f;
return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), start, end, CollisionWidth, ref collisionPoint);
}
}
}
This is normal state and it's hitting on the end of the blade.
This happens if something increasing the attack speed.
Rapier as Item code:
using SomeStuffMod.Content.Projectiles;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria.Localization;
namespace SomeStuffMod.Content.Items.Rapiers
{
public class BlackSteelRapier : ModItem
{
public override void SetDefaults()
{
Item.damage = 145;
Item.width = 50;
Item.height = 50;
Item.useTime = 7;
Item.crit = 26;
Item.useAnimation = 7;
Item.DamageType = DamageClass.MeleeNoSpeed;
Item.useStyle = ItemUseStyleID.Rapier;
Item.knockBack = 7;
Item.value = Item.buyPrice(gold: 10);
Item.rare = ItemRarityID.Gray;
Item.UseSound = SoundID.Item71;
Item.autoReuse = true;
Item.noUseGraphic = true;
Item.noMelee = true;
Item.shoot = ModContent.ProjectileType<BlackSteelRapierProjectile>();
Item.shootSpeed = 9f;
}
public override void AddRecipes()
{
Recipe recipe = Recipe.Create(ModContent.ItemType<Items.Rapiers.BlackSteelRapier>());
recipe.AddIngredient<Items.BlackSteelBar>(10);
recipe.AddIngredient(ItemID.LihzahrdBrick, 5);
recipe.AddTile(TileID.LihzahrdFurnace);
recipe.Register();
}
}
}
Rapier as Projectile code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Enums;
using Terraria.ModLoader;
using System;
using Terraria.ID;
using Microsoft.Xna.Framework.Graphics;
namespace SomeStuffMod.Content.Projectiles
{
public class BlackSteelRapierProjectile : ModProjectile
{
public const int FadeInDuration = 15;
public const int FadeOutDuration = 18;
public const int TotalDuration = 30;
public float CollisionWidth => 10f * Projectile.scale;
public int Timer
{
get => (int)Projectile.ai[0];
set => Projectile.ai[0] = value;
}
public override void SetDefaults()
{
Projectile.Size = new Vector2(42);
Projectile.aiStyle = ProjAIStyleID.ShortSword;
Projectile.friendly = true;
Projectile.penetrate = -1;
Projectile.tileCollide = false;
Projectile.scale = 2.8f;
Projectile.DamageType = DamageClass.Melee;
Projectile.ownerHitCheck = true;
Projectile.extraUpdates = 1;
Projectile.timeLeft = 360;
Projectile.hide = true;
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
target.AddBuff(BuffID.BrokenArmor, 180);
target.AddBuff(BuffID.Weak, 180);
target.AddBuff(BuffID.Ichor, 180);
target.AddBuff(BuffID.Venom, 180);
}
public override void AI()
{
Player player = Main.player[Projectile.owner];
Timer += 1;
if (Timer >= TotalDuration)
{
Projectile.Kill();
return;
}
else
{
player.heldProj = Projectile.whoAmI;
}
Projectile.Opacity = Utils.GetLerpValue(0f, FadeInDuration, Timer, clamped: true) * Utils.GetLerpValue(TotalDuration, TotalDuration - FadeOutDuration, Timer, clamped: true);
Vector2 playerCenter = player.RotatedRelativePoint(player.MountedCenter, reverseRotation: false, addGfxOffY: false);
Projectile.Center = playerCenter + Projectile.velocity * (Timer - 1f);
Projectile.spriteDirection = (Vector2.Dot(Projectile.velocity, Vector2.UnitX) >= 0f).ToDirectionInt();
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2 - MathHelper.PiOver4 * Projectile.spriteDirection;
SetVisualOffsets();
}
private void SetVisualOffsets()
{
const int HalfSpriteWidth = 89 / 2;
const int HalfSpriteHeight = 90 / 2;
int HalfProjWidth = Projectile.width / 2;
int HalfProjHeight = Projectile.height / 2;
DrawOriginOffsetX = 1;
DrawOffsetX = -(HalfSpriteWidth - HalfProjWidth);
DrawOriginOffsetY = -(HalfSpriteHeight - HalfProjHeight);
if (Projectile.spriteDirection == 1)
{
DrawOriginOffsetX = -(HalfProjWidth - HalfSpriteWidth);
DrawOffsetX = (int)-DrawOriginOffsetX * 2;
DrawOriginOffsetY = 0;
}
else
{
DrawOriginOffsetX = (HalfProjWidth - HalfSpriteWidth);
DrawOffsetX = 0;
DrawOriginOffsetY = 0;
}
}
public override bool ShouldUpdatePosition()
{
return false;
}
public override void CutTiles()
{
DelegateMethods.tilecut_0 = TileCuttingContext.AttackProjectile;
Vector2 start = Projectile.Center;
Vector2 end = start + Projectile.velocity.SafeNormalize(-Vector2.UnitY) * 10f;
Utils.PlotTileLine(start, end, CollisionWidth, DelegateMethods.CutTiles);
}
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
{
Vector2 start = Projectile.Center;
Vector2 end = start + Projectile.velocity * 27f;
float collisionPoint = 0f;
return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), start, end, CollisionWidth, ref collisionPoint);
}
}
}