#Shoot projectile on Y-rotation only

1 messages · Page 1 of 1 (latest)

ionic estuary
#

how can i make my projectile to only shoot at the same level as the player and not including the player's head rotation on x axis so it wont get shoot up or down.

lavish berry
lavish berry
# ionic estuary how can i make my projectile to only shoot at the same level as the player and n...

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 });
        }
    });
});
ionic estuary
# lavish berry Here is an example using custom components, I haven't tested it but it should wo...

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 });