how can I make applyKnockback () always take me to the height I want, e.g. 256?
code generated by chatGPT:
import {world, Vector} from "@minecraft/server";
world.events.beforeItemUseOn.subscribe((data)=>{
const {source} = data;
const playerLocation = source.location.y;
const targetLocation = 256;
if (playerLocation > 0) {
const difference = targetLocation - playerLocation; // calculate the height difference in blocks
const currentBlockY = Math.floor(playerLocation); // convert the player's current height to block coordinates
const magnitude = difference * 16; // calculate the magnitude of the required vertical impulse in height units
const targetBlockY = currentBlockY + magnitude; // calculate the target height in block coordinates
source.applyKnockback(1, 1, 0, targetBlockY); // apply the vertical impulse in block coordinates
}
});
does not work