#Knockback
1 messages · Page 1 of 1 (latest)
• 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.
need custom knockback
world.afterEvents.entityHit.subscribe((event)=>{
let source = event.hitEntity
if (source.typeId === 'minecraft:player') {
source.applyKnockback(source.location.x,source.location.z,1,1)
}
})```
lemme test
@tender turtle
changed afterEvents to events and its throwing me 6 blocks high
got the things correct but its tilting the hit person to the right
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)
}
})```
add ? expression to prevent errors when you hit something else other than an entity. such as block hits (hitBlock)
source?.typeId
what do you need