#The best knockback?

1 messages · Page 1 of 1 (latest)

worn scroll
#

I'm trying to do custom low knockback like ZEQA ,but I think this is still not perfect,who can help me revamp it with better value and structure?

#
import { world, Player } from '@minecraft/server';

const config = {
    baseHorizontalKB: 0.09,
    baseVerticalKB: 0.2,
    sprintMultiplier: 1.2,
    comboReduction: 0.8
};

const lastHitTimes = new Map();

world.afterEvents.entityHitEntity.subscribe((event) => {
    const attacker = event.damagingEntity;
    const victim = event.hitEntity;

    if (!(attacker instanceof Player) || !(victim instanceof Player)) return;

    const now = Date.now();
    const lastHitTime = lastHitTimes.get(victim) || 0;
    const isCombo = now - lastHitTime < 1000;
    lastHitTimes.set(victim, now);

    const attackerLocation = attacker.location;
    const victimLocation = victim.location;

    let knockbackX = victimLocation.x - attackerLocation.x;
    let knockbackZ = victimLocation.z - attackerLocation.z;
    const magnitude = Math.sqrt(knockbackX ** 2 + knockbackZ ** 2);

    if (magnitude !== 0) {
        knockbackX /= magnitude;
        knockbackZ /= magnitude;
    }

    let horizontalKB = config.baseHorizontalKB;
    let verticalKB = config.baseVerticalKB;

    if (attacker.isSprinting) {
        horizontalKB *= config.sprintMultiplier;
    }

    if (isCombo) {
        horizontalKB *= config.comboReduction;
        verticalKB *= config.comboReduction;
    }

    victim.applyKnockback(knockbackX * horizontalKB, knockbackZ * horizontalKB, horizontalKB, verticalKB);
});
#

This is my code and value, but this is still not perfect bc I improve it by ai ,I hope someone can revamp it better and similar value

worn scroll
#

I want it closer between players with original verticalKB

#

Just restructure it and change horizontalKB

hot aspen
#

hmmm i used to make one back in the day, ill try messing with ur code later at night

worn scroll
hot aspen
#

hopefully i can do this

worn scroll
worn scroll
hot aspen
worn scroll