#The best knockback?
1 messages · Page 1 of 1 (latest)
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
It seems it is still a knockback far when player pvp
I want it closer between players with original verticalKB
Just restructure it and change horizontalKB
hmmm i used to make one back in the day, ill try messing with ur code later at night
Ok thx hope U find the best value
ive seen this vid in hyrc xd
hopefully i can do this
Oh lol
Really?? I will be very grateful for it!! Because I'm finding the low knockback like ZEQA for long time
same, ive been trying this too, since ive done it on mobss, ill try on players
Yea I saw your mcpedl before, U used to say U will make player version