tModLoader Need help with custom throwing weapon

Fabu ♡

Terrarian
I made a custom throwing weapon, which is basically a crystalized version of the Throwing Knife.

When I throw the knife it rotates like a shuriken, instead of flying in a straight line and rotating when it falls to the ground.

Can anyone give me advice?

Here's the code of the projectile:

Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using System;

namespace FabusMod.Projectiles
{
    public class CrystalThrowingKnife : ModProjectile
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Crystal Throwing Knife");
        }

        public override void SetDefaults()
        {
            projectile.width = 18;
            projectile.height = 24;
            projectile.aiStyle = 2;
            projectile.friendly = true;
            projectile.melee = true;
            projectile.penetrate = 2;
        }     

        public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
        {
            if(targetHitbox.Width > 8 && targetHitbox.Height > 8)
            {
                targetHitbox.Inflate(-targetHitbox.Width / 8, -targetHitbox.Height / 8);
            }
            return projHitbox.Intersects(targetHitbox);
        }

        public override void Kill(int timeLeft)
        {
            Main.PlaySound(0, (int)projectile.position.X, (int)projectile.position.Y, 1, 1f, 0f);
            Vector2 usePos = projectile.position;
            Vector2 rotVector = (projectile.rotation - MathHelper.ToRadians(90f)).ToRotationVector2();
            usePos += rotVector * 16f;

            int item = 0;
           
            if(Main.netMode == 1 && item >= 0)
            {
                NetMessage.SendData(MessageID.KillProjectile);
            }
           
            if (Main.rand.NextFloat() < 0.18f)
            {
                item = Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, mod.ItemType<Items.Weapons.CrystalThrowingKnife>(), 1, false, 0, false, false);
            }
           
            if (Main.netMode == 1 && item >= 0)
            {
                NetMessage.SendData(Terraria.ID.MessageID.SyncItem, -1, -1, null, item, 1f, 0f, 0f, 0, 0, 0);
            }
        }

        private const float maxTicks = 60f;
        private const int alphaReducation = 25;

       
    }
}
 
You can try adding "aiType = ProjectileID.ThrowingKnife;" to setdefaults.

What is happening is aiStyle 2 is used for many different projectiles, but you aren't specifying that you'd like to use the sub-behavior of the throwing knife, so it uses the default behavior.
 
You can try adding "aiType = ProjectileID.ThrowingKnife;" to setdefaults.

What is happening is aiStyle 2 is used for many different projectiles, but you aren't specifying that you'd like to use the sub-behavior of the throwing knife, so it uses the default behavior.

Thank youu <3
 
Back
Top Bottom