#applyKnockback ()

1 messages · Page 1 of 1 (latest)

long oasis
#

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

long oasis
#

b.ump

fathom pike
#
let s: Entity;
s.applyKnockback()```
vapid shuttleBOT
#
Debug Result

There are 2 errors in this [code](#1088604291272552530 message):

<repl>.js:1:8 - error TS8010: Type annotations can only be used in TypeScript files.

1 let s: Entity;
         ~~~~~~
<repl>.js:2:3 - error TS2554: Expected 4 arguments, but got 0.

2 s.applyKnockback()
    ~~~~~~~~~~~~~~~~

  @minecraft/server.d.ts:556:28
    556             applyKnockback(directionX: number, directionZ: number, horizontalStrength: number, verticalStrength: number): void;
                                   ~~~~~~~~~~~~~~~~~~
    An argument for 'directionX' was not provided.

fathom pike
#

there is no y

#

i think vertical thing is for y

#

u can solve this with right triangle equation

long oasis
#

💀

fathom pike
#

?