import { system, Player } from '@minecraft/server';
////Player/////
system.afterEvents.scriptEventReceive.subscribe(({ sourceEntity: player, id }) => {
if (id !== 'script:swing') return;
// Verificar se o sourceEntity é um jogador
if (!(player instanceof Player)) return;
// Obter a direção de visão do jogador
const { x, y, z } = player.getViewDirection();
// Normalizar o vetor horizontal (x, z) para garantir direção consistente
const horizontalMagnitude = Math.sqrt(x * x + z * z);
const normalizedX = x / horizontalMagnitude;
const normalizedZ = z / horizontalMagnitude;
// Ajustar a força para alcançar 10 blocos
const horizontalForce = 1.2; // Valor ajustado para 10 blocos
const verticalForce = 0.1; // Ajuste para simular um leve salto (opcional)
// Aplicar o knockback ao jogador
player.applyKnockback(normalizedX, normalizedZ, horizontalForce, verticalForce);
})
#[solved] Why can't I use "/scriptevent script:swing" in Minecraft version 1.21.70?
1 messages · Page 1 of 1 (latest)
applyKnockback got changed in v2.0 now it expects VectorXZ and vertical strength, you can multiply the X and Z by horizontal strength, here is an example
player.applyKnockback({ x: normalizedX * horizontalForce, z: normalizedZ * horizontalForce }, verticalForce);
also if you're not using v2.0 then don't change applyKnockback, and show any errors if there are any
I will test it right now. Thank you very much!
It worked perfectly!