#how can i create a script that can fire projectile with custom properties like fireRate, damage etc.

1 messages · Page 1 of 1 (latest)

carmine drift
#

You'll either have to learn a bit about addon creating or find a mod online. I doubt anyone will just make one

haughty nebula
#

bump

wintry gale
#

i think you create a custom entity , that willl act like a bullet

#

you put projectile compoenent inside its entity file

#

then in script you can do

entity.getComponent(`minecraft:projectile`)```
#

and there is a .shoot() method

rugged gate
wintry gale
finite gate
#
export function shootProjectile(
  entity: Entity,
  typeId: string,
  power: number,
  tag?: string
) {
  const headLoc = entity.getHeadLocation();
  const viewVector = entity.getViewDirection();
  const direction = {
    x: headLoc.x + viewVector.x,
    y: headLoc.y + viewVector.y,
    z: headLoc.z + viewVector.z,
  };
  const vel = {
    x: viewVector.x * power,
    y: viewVector.y * power,
    z: viewVector.z * power,
  };
  const projectile = entity.dimension.spawnEntity(typeId, direction);
  if (tag) projectile.addTag(`${tag}`);

  const shotProj = projectile.getComponent(EntityComponentTypes.Projectile);
  if (shotProj == undefined) return;

  shotProj.owner = entity;
  shotProj.shoot(vel);
}
rugged gate