#How to make a script that fires multiple projectiles at different angles when used?

1 messages · Page 1 of 1 (latest)

pallid quartz
#

I already kind of know how to make an item generate and fire a projectile when used via scripts, but how do I make it fire multiple projectiles, each being some distance apart? I want to fire five projectiles in the player's view direction.

ocean plank
#

function shoot(player, projectile, forwardOffset, speed, launchPower) {
const { x, y, z } = player.location;
const direction = player.getViewDirection();

const spawnPos = {
    x: player.location.x + player.getViewDirection().x * forwardOffset,
    y: player.location.y + 1.5,
    z: player.location.z + player.getViewDirection().z * forwardOffset,
};

const arrow = player.dimension.spawnEntity(projectile, spawnPos);


const projectileComp = arrow.getComponent("minecraft:projectile");



const velocity = {
    x: direction.x * speed,
    y: direction.y * speed,
    z: direction.z * speed,
}



projectileComp.shoot(velocity, {
    uncertainty: 0,
    launchPower: launchPower,
    owner: player,

});

}

#

abit late

#

but just change this to multiple directions

placid ferry
#

same goes to destructing player location.

#

and just use player.getHeadLocation()

ocean plank