#why this code not working

1 messages · Page 1 of 1 (latest)

hot beacon
#
world.afterEvents.projectileHitEntity.subscribe((data) => {
  for (const player of world.getPlayers()) {
  const [projectile] = [data.projectile,];
  if (projectile?.typeId == "minecraft:snowball") {
      player.runCommandAsync('playsound random.orb')
      const botloc = data.getEntityHit().location
    const playerloc = player.location
    const directionX = playerloc.x - botloc.x
    const directionZ = playerloc.z - botloc.z
    const magnitude = Math.sqrt(directionX * directionX + directionZ * directionZ)
    const newdirX = directionX / magnitude
    const newdirZ = directionZ / magnitude
      hurtEntity.clearVelocity();
      if (!player.hasTag('highkb')) {
        data.getEntityHit().applyImpulse({ x: newdirX / 3.33, y: 0.36, z: newdirZ / 3.33 });
        } else if (player.hasTag('highkb')) {
          data.getEntityHit().applyImpulse({ x: newdirX / 3.33, y: 0.37, z: newdirZ / 3.33 });
        }
  }
}
});

i dont know how to get the entity that was hit by snowball

barren scroll
#

you gotta double check on docs

hot beacon
#

i read the doc that part but dont understand as i need example to learn tho

tacit ingot
# hot beacon i read the doc that part but dont understand as i need example to learn tho

You should just check what the property/method return into, so you'll know what to write next to it.

Example in the docs it says that getEntityHit() return EntityHitInformation, in which if you click that EntityHitInformation you will go to its interface, where you can see the list of properties/methods available. In this case, there's entity property only, so that's what you'll gonna write next to getEntityHit(). Not everything need examples, if docs could make it obvious. You just have to know how to use docs.

Contents of the @minecraft/server.EntityHitInformation class.