From 335d9405422b9e6663cb45a8aee310ce1e15c38a Mon Sep 17 00:00:00 2001 From: linuxdev Date: Wed, 10 Jun 2026 18:24:17 +0800 Subject: [PATCH] fix(Predator): add bulletSpawnDistance for concentric bullet spawn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Predator's 3 barrels have different visual sizes (110, 95, 80) which was causing their bullets to spawn at different distances from tank center — small bullet ahead, big bullet behind. In diep.io all 3 spawn concentrically. Added optional bulletSpawnDistance field to BarrelDefinition. When set, it overrides barrel visual size for bullet spawn distance calculation. Set to 110 on all 3 Predator barrels for concentric spawn. Also fixed: barrel.distance in Bullet.ts was not scaled by scaleFactor, inconsistent with Barrel.ts where it is. Signed-off-by: linuxdev --- src/Const/TankDefinitions.json | 3 +++ src/Const/TankDefinitions.ts | 2 ++ src/Entity/Tank/Projectile/Bullet.ts | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Const/TankDefinitions.json b/src/Const/TankDefinitions.json index 5350f193..0d0208cd 100644 --- a/src/Const/TankDefinitions.json +++ b/src/Const/TankDefinitions.json @@ -3820,6 +3820,7 @@ "angle": 0, "offset": 0, "size": 110, + "bulletSpawnDistance": 110, "width": 42, "delay": 0, "reload": 3, @@ -3842,6 +3843,7 @@ "angle": 0, "offset": 0, "size": 95, + "bulletSpawnDistance": 110, "width": 56.7, "delay": 0.2, "reload": 3, @@ -3864,6 +3866,7 @@ "angle": 0, "offset": 0, "size": 80, + "bulletSpawnDistance": 110, "width": 71.39999999999999, "delay": 0.4, "reload": 3, diff --git a/src/Const/TankDefinitions.ts b/src/Const/TankDefinitions.ts index 884536d7..aaf2d379 100644 --- a/src/Const/TankDefinitions.ts +++ b/src/Const/TankDefinitions.ts @@ -72,6 +72,8 @@ export interface BarrelDefinition { offset: number; /** The y offset of the barrel (distance from the tanks main body) at base radius (50). Will have no effect on clientside tankrendering.*/ distance?: number; + /** Overrides the distance from tank center at which bullets spawned by this barrel appear. Defaults to `size` if not set. */ + bulletSpawnDistance?: number; /** The size of the barrel. Think of Sniper, the longer side is the size. */ size: number; /** The width of the barrel. Think of Sniper, the shorter side is the width. Width is used to determine bullet size */ diff --git a/src/Entity/Tank/Projectile/Bullet.ts b/src/Entity/Tank/Projectile/Bullet.ts index 92460611..045850b9 100644 --- a/src/Entity/Tank/Projectile/Bullet.ts +++ b/src/Entity/Tank/Projectile/Bullet.ts @@ -96,9 +96,10 @@ export default class Bullet extends LivingEntity { this.lifeLength = bulletDefinition.lifeLength * 75; const {x, y} = tank.getWorldPosition(); + const bulletSpawnDistance = (barrel.definition.bulletSpawnDistance ?? barrel.definition.size) * scaleFactor; - this.positionData.values.x = x + (Math.cos(shootAngle) * barrel.physicsData.values.size) - Math.sin(shootAngle) * barrel.definition.offset * scaleFactor + Math.cos(shootAngle) * (barrel.definition.distance || 0); - this.positionData.values.y = y + (Math.sin(shootAngle) * barrel.physicsData.values.size) + Math.cos(shootAngle) * barrel.definition.offset * scaleFactor + Math.sin(shootAngle) * (barrel.definition.distance || 0); + this.positionData.values.x = x + (Math.cos(shootAngle) * bulletSpawnDistance) - Math.sin(shootAngle) * barrel.definition.offset * scaleFactor + Math.cos(shootAngle) * ((barrel.definition.distance ?? 0) * scaleFactor); + this.positionData.values.y = y + (Math.sin(shootAngle) * bulletSpawnDistance) + Math.cos(shootAngle) * barrel.definition.offset * scaleFactor + Math.sin(shootAngle) * ((barrel.definition.distance ?? 0) * scaleFactor); this.positionData.values.angle = shootAngle; }