tModLoader Help projectile fix as it is passing through?

notanoman

Terrarian
I am trying to make a projectile that is a chlorophyte bullet that has less particles, the thing is that my projectile has a GAP where enemies can be safe through but the only fix i see is making the projectile hitbox bigger,

terrrrr.png


If i make the projectile bigger the bullets wont fit on any horizontal 1 block gap.

terrr2.png
terrr.png


I want to make this like the all the bullets where it doesn't have the empty gap. I was thinking if there was a code in which the projectile hitbox rotate like the sprites of the projectile, but i cant find anything
(ps. im a beginner at the tmodloader codes atm.)

The problems:
1. If i make the hitbox of the bullet smaller, it wont have the problem of the 1 block gap, it will have the problem of the empty bullet gaps again.
2. Same goes the other way around, If i make the hit box of the bullet bigger, it wont have the problem of the empty bullet gaps, but it wont fit on the 1 block horizontal gap.

If you need the code for my projectile here it is:

using System; //what sources the code uses, these sources allow for calling of terraria functions, existing system functions and microsoft vector functions (probably more)
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BulletHose.Items.Projectiles
{
public class lesslagbullet : ModProjectile
{
public override void SetDefaults()
{
projectile.width = 30; //sprite is 2 pixels wide
projectile.height = 2; //sprite is 20 pixels tall
projectile.aiStyle = 0; //projectile moves in a straight line
projectile.friendly = true; //player projectile
projectile.hostile = false; //Tells the game whether it is hostile to players or not
projectile.ranged = true; //ranged projectile
projectile.penetrate = 1; //How many monsters the projectile can penetrate. (OnTileCollide below also decrements penetrate for bounces as well)
projectile.tileCollide = true; //Can the projectile collide with tiles?
projectile.ignoreWater = true; //Tells the game whether or not projectile will be affected by water
projectile.timeLeft = 600; //lasts for 600 frames/ticks. Terraria runs at 60FPS, so it lasts 10 seconds.
aiType = ProjectileID.Bullet; //This clones the exact AI of the vanilla projectile Bullet.
}
public override void AI()
{
Lighting.AddLight(projectile.position, 0.0f, 0.45f, 0.0f);

projectile.rotation = projectile.velocity.ToRotation() + MathHelper.ToRadians(0f);

float num132 = (float)Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y));
float num133 = projectile.localAI[0];
if (num133 == 0f)
{
projectile.localAI[0] = num132;
num133 = num132;
}
float num134 = projectile.position.X;
float num135 = projectile.position.Y;
float num136 = 300f;
bool flag3 = false;
int num137 = 0;
if (projectile.ai[1] == 0f)
{
for (int num138 = 0; num138 < 200; num138++)
{
if (Main.npc[num138].CanBeChasedBy(this, false) && (projectile.ai[1] == 0f || projectile.ai[1] == (float)(num138 + 1)))
{
float num139 = Main.npc[num138].position.X + (float)(Main.npc[num138].width / 2);
float num140 = Main.npc[num138].position.Y + (float)(Main.npc[num138].height / 2);
float num141 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num139) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num140);
if (num141 < num136 && Collision.CanHit(new Vector2(projectile.position.X + (float)(projectile.width / 2), projectile.position.Y + (float)(projectile.height / 2)), 1, 1, Main.npc[num138].position, Main.npc[num138].width, Main.npc[num138].height))
{
num136 = num141;
num134 = num139;
num135 = num140;
flag3 = true;
num137 = num138;
}
}
}
if (flag3)
{
projectile.ai[1] = (float)(num137 + 1);
}
flag3 = false;
}
if (projectile.ai[1] > 0f)
{
int num142 = (int)(projectile.ai[1] - 1f);
if (Main.npc[num142].active && Main.npc[num142].CanBeChasedBy(this, true) && !Main.npc[num142].dontTakeDamage)
{
float num143 = Main.npc[num142].position.X + (float)(Main.npc[num142].width / 2);
float num144 = Main.npc[num142].position.Y + (float)(Main.npc[num142].height / 2);
if (Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num143) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num144) < 1000f)
{
flag3 = true;
num134 = Main.npc[num142].position.X + (float)(Main.npc[num142].width / 2);
num135 = Main.npc[num142].position.Y + (float)(Main.npc[num142].height / 2);
}
}
else
{
projectile.ai[1] = 0f;
}
}
if (!projectile.friendly)
{
flag3 = false;
}
if (flag3)
{
float num145 = num133;
Vector2 vector10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
float num146 = num134 - vector10.X;
float num147 = num135 - vector10.Y;
float num148 = (float)Math.Sqrt((double)(num146 * num146 + num147 * num147));
num148 = num145 / num148;
num146 *= num148;
num147 *= num148;
int num149 = 8;
projectile.velocity.X = (projectile.velocity.X * (float)(num149 - 1) + num146) / (float)num149;
projectile.velocity.Y = (projectile.velocity.Y * (float)(num149 - 1) + num147) / (float)num149;
}
}

public override void Kill(int timeLeft)
{
Collision.HitTiles(projectile.position, projectile.velocity, projectile.width, projectile.height);
Main.PlaySound(SoundID.Item10, projectile.position);
}
}
}



--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Bonus Question:
also if you know something about the muzzle offset, where do i put the coordinates to adjust the muzzle offset? because if i make the hitbox also smaller the bullets positions are not correct.

terrr3.png


public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2 muzzleOffset = Vector2.Normalize(new Vector2(speedX, speedY)) * 25f;
if (Collision.CanHit(position, 0, 0, position + muzzleOffset, 0, 0))
{
position += muzzleOffset;
}
return true;
}
 
Back
Top Bottom