#Knockback

1 messages · Page 1 of 1 (latest)

crude storm
#

need a script that if they hit a entity and if its a player it'll apply knockback

upper egret
#

• Subscribe to entityHit
• Check if its a player
• get the attacker Vector3 and hurt entity Vector3
• do some Simple Math
• Either use applyImpulse or applyKnockback

#

Honestly, why do you need this? You literally take knockback when any entity hit you.

tender turtle
crude storm
#

@tender turtle

#

changed afterEvents to events and its throwing me 6 blocks high

crude storm
#
world.events.entityHit.subscribe((event)=>{
  let source = event.hitEntity
  if (source.typeId === 'minecraft:player') {
    source.applyKnockback(source.location.x,source.location.z,-0.4,0.2)
  }
  })```
upper egret
#

add ? expression to prevent errors when you hit something else other than an entity. such as block hits (hitBlock)
source?.typeId

copper hazel
#

what do you need