ProjectileWeapon

@three-blocks/proPhysicsWeaponsProjectileWebGPUWebGL
new ProjectileWeapon(views : Object, type : string, index : number, mesh : THREE.InstancedMesh, physics : Physics, properties : Object)
Extends
Weapon

ProjectileWeapon - Projectile weapon proxy extension

Extends the base Weapon class with projectile-specific properties like speed, gravity, drag, lifetime, and AoE radius. Projectiles follow physics-based trajectories with automatic visual mesh syncing.

Mesh instances automatically sync with active projectiles via Three.js onBeforeRender callbacks with smooth interpolation. Requires InstancedMesh created via physics.createMeshPool().

Constructor Parameters
viewsObject
SharedArrayBuffer views
typestring
Weapon type
indexnumber
Weapon slot index
meshTHREE.InstancedMesh
InstancedMesh created via physics.createMeshPool()
Physics instance reference
propertiesObject
Weapon configuration properties
Example
import { Physics, WeaponType, WeaponEvent, ProjectilePreset } from '@three-blocks/pro';

// Grenade launcher (slow-firing, small pool)
const grenadeTemplate = new THREE.Mesh(sphereGeometry, material);
const grenadePool = physics.createMeshPool(grenadeTemplate, 2, scene);
const grenade = await physics.addWeapon(WeaponType.PROJECTILE, grenadePool, {
  damage: 100,
  ...ProjectilePreset.GRENADE,
});

grenade.weapon.addEventListener(WeaponEvent.EXPLODE, (event) => {
  spawnExplosion(event.position, event.aoeRadius);
});

grenade.weapon.fireFromCamera(); // Meshes sync automatically!

// Tower defense (rapid-fire, larger pool)
const arrowTemplate = new THREE.Mesh(arrowGeometry, arrowMaterial);
const arrowPool = physics.createMeshPool(arrowTemplate, 20, scene);
const tower = await physics.addWeapon(WeaponType.PROJECTILE, arrowPool, {
  damage: 35,
  ...ProjectilePreset.ARROW,
});

tower.weapon.fire(towerBodyIndex, { direction: [...] }); // Automatic syncing!

Properties

.meshAutoUpdate : boolean

Automatically sync mesh position with projectile physics. Set to false to manually control mesh position.

.speed : number

Get projectile speed (m/s).

.speed : number

Set projectile speed (m/s).

.gravity : number

Get gravity multiplier (1.0 = normal gravity).

.gravity : number

Set gravity multiplier (1.0 = normal gravity).

.drag : number

Get drag coefficient (air resistance).

.drag : number

Set drag coefficient (air resistance).

.lifetime : number

Get projectile lifetime in seconds.

.lifetime : number

Set projectile lifetime in seconds.

.aoeRadius : number

Get area-of-effect radius (0 = no AoE).

.aoeRadius : number

Set area-of-effect radius (0 = no AoE).

Methods

dispose#

dispose()

Dispose projectile weapon and clean up resources. Removes mesh pool associations and event listeners.