#Shoot projectile on Y-rotation only
1 messages · Page 1 of 1 (latest)
I don't know if it is possible just by editing the projectile json file, but with scripts it is possible
i see, thank you
Here is an example using custom components, I haven't tested it but it should work
import { world } from '@minecraft/server'
world.beforeEvents.worldInitialize.subscribe(initEvent => {
initEvent.itemComponentRegistry.registerCustomComponent('namespace:example', {
onUse: e => {
const { source } = e;
// The projectile entity identifier
const projectile = 'example:identifier';
// The direction of the projectile
const viewDir = source.getViewDirection(),
head = source.getHeadLocation(),
direction = { x: head.x + viewDir.x, y: head.y - 0.5, z: head.z + viewDir.z };
// The power of the projectile
const power = { x: 0.75, y: 0, z: 0.75 };
// Shoot the projectile
source.dimension.spawnEntity(projectile, direction).getComponent('minecraft:projectile').shoot({ x: viewDir.x*power.x, y: viewDir.y*power.y, z: viewDir.z*power.z }, { owner: source });
}
});
});
thanks it worked perfectly!
const projectile = 'ale:tsunami';
const viewDir = player.getViewDirection()
const location = player.location
const direction = { x: location.x + viewDir.x, y: location.y - 0.5, z: location.z + viewDir.z }
const velocity = { x: 0.7, y: 0, z: 0.7 }
const tsunami = world.getDimension('overworld').spawnEntity(projectile, direction);
const projectileComp = tsunami.getComponent('minecraft:projectile');
projectileComp?.shoot({ x: viewDir.x*velocity.x, y: viewDir.y*velocity.y, z: viewDir.z*velocity.z }, { owner: player });