Wiki 9Minecraft Wiki 9Minecraft

Entity Attacks and Targeting

Configure melee, ranged, and area-of-effect combat behaviors for custom Bedrock entities.

6Sections
5Code examples
4Known errors

An entity in Minecraft Bedrock cannot deal damage on its own without combining three distinct mechanics: a targeting goal to pick a victim, an attack behavior to close the distance or aim, and a damage attribute to define the hit strength. Whether you are building a simple zombie variant or a custom ranged turret, you will assemble its combat loop from these separate behavior pack components.

The Three Parts of an Attack

New creators often add an attack component to an entity file and wonder why the mob stands completely still when spawned next to a player. Bedrock separates the concept of wanting to fight from the physical act of fighting. Every hostile or defensive mob requires a targeting component, an offensive movement or action component, and a damage stat.

Targeting components (prefixed with "minecraft:behavior.nearest_attackable_target" or "minecraft:behavior.hurt_by_target") do not move the entity; they simply populate the entity's internal target slot. Attack behaviors read that target slot, pathfind toward the victim, and trigger the attack. Finally, the "minecraft:attack" attribute defines how many health points are deducted when a melee hit actually connects, while ranged behaviors delegate their damage to a separate projectile entity.

Acquiring a Target

Before any attack behavior can run, the entity needs a valid target. The two standard goals for this are "minecraft:behavior.hurt_by_target" (which makes the mob retaliate against whatever hit it last) and "minecraft:behavior.nearest_attackable_target" (which actively scans for prey matching a filter).

Most hostile mobs use both. By giving "hurt_by_target" a lower priority number (meaning higher importance in Bedrock's AI system), the mob will stop chasing a distant villager to defend itself against a player striking it up close. You must also include "minecraft:follow_range" in the entity's components so the targeting AI knows how far out to scan.

BP/entities/custom_guard.json
{
  "format_version": "1.20.80",
  "minecraft:entity": {
    "description": {
      "identifier": "wiki:custom_guard",
      "is_spawnable": true,
      "is_summonable": true
    },
    "components": {
      "minecraft:follow_range": {
        "value": 24,
        "max": 24
      },
      "minecraft:behavior.hurt_by_target": {
        "priority": 1
      },
      "minecraft:behavior.nearest_attackable_target": {
        "priority": 2,
        "must_see": true,
        "reselect_targets": true,
        "within_radius": 16.0,
        "entity_types": [
          {
            "filters": {
              "any_of": [
                { "test": "is_family", "subject": "other", "value": "monster" },
                { "test": "is_family", "subject": "other", "value": "player" }
              ]
            },
            "max_dist": 16
          }
        ]
      }
    }
  }
}

Melee Attacks

Standard close-quarters combat uses "minecraft:behavior.melee_attack" paired with the "minecraft:attack" component. The behavior tells the entity to pathfind directly into the target's bounding box and swing at a set interval, while "minecraft:attack" sets the raw damage and optional status effects like poison or wither.

Remember that "minecraft:behavior.melee_attack" relies on the entity's navigation and movement components to actually reach the target. If your entity lacks "minecraft:movement.basic", "minecraft:navigation.walk" (or an equivalent), and a "minecraft:movement" speed value, it will acquire a target and rotate toward it, but remain rooted to the spot.

FieldWhat it doesNotes
damageHealth points removed on hit (2 points = 1 heart).Lives inside "minecraft:attack". Can be a single number or a range array like [4, 6].
effect_nameStatus effect applied when the melee hit lands.Lives inside "minecraft:attack". Uses vanilla effect identifiers such as "poison" or "weakness".
cooldown_timeSeconds between melee swings.Lives inside "minecraft:behavior.melee_attack". Defaults to 1.0.
speed_multiplierMultiplies base movement speed while chasing a target.Lives inside "minecraft:behavior.melee_attack".
track_targetContinues following the target even if line of sight breaks.Boolean inside "minecraft:behavior.melee_attack".
BP/entities/custom_brawler.json
{
  "format_version": "1.20.80",
  "minecraft:entity": {
    "description": {
      "identifier": "wiki:custom_brawler",
      "is_spawnable": true,
      "is_summonable": true
    },
    "components": {
      "minecraft:movement": {
        "value": 0.28
      },
      "minecraft:movement.basic": {},
      "minecraft:navigation.walk": {
        "can_path_over_water": true
      },
      "minecraft:attack": {
        "damage": 6,
        "effect_name": "slowness",
        "effect_duration": 5
      },
      "minecraft:behavior.melee_attack": {
        "priority": 3,
        "speed_multiplier": 1.25,
        "track_target": true,
        "cooldown_time": 1.0
      }
    }
  }
}

Delayed and Animated Melee Attacks

Standard melee attacks apply damage the exact tick the entity gets within reach. For larger monsters with slow, telegraphed wind-up animations (like the Ravager or Iron Golem), instantaneous damage feels unfair to players. You can swap "minecraft:behavior.melee_attack" for "minecraft:behavior.delayed_attack" to synchronize the damage frame with a resource pack animation.

With "minecraft:behavior.delayed_attack", the entity enters an attack state when in range, waits for the duration defined in "attack_duration", and only applies the damage when the timer crosses the "hit_delay_pct" threshold. If the player backs out of the reach multiplier before that percentage is reached, the swing misses.

BP/entities/heavy_brute.json
{
  "format_version": "1.20.80",
  "minecraft:entity": {
    "description": {
      "identifier": "wiki:heavy_brute",
      "is_spawnable": true,
      "is_summonable": true
    },
    "components": {
      "minecraft:attack": {
        "damage": 14
      },
      "minecraft:behavior.delayed_attack": {
        "priority": 2,
        "attack_duration": 1.5,
        "hit_delay_pct": 0.6,
        "track_target": true,
        "reach_multiplier": 2.0,
        "speed_multiplier": 1.0
      }
    }
  }
}

Ranged Attacks

To make an entity shoot projectiles, use "minecraft:behavior.ranged_attack" combined with "minecraft:shooter". Unlike melee attacks, the "minecraft:attack" component is not used here. Instead, the damage, gravity, and impact effects are defined on the projectile entity itself.

The "minecraft:shooter" component specifies which entity identifier to spawn as ammunition via the "def" field. The "minecraft:behavior.ranged_attack" goal controls how close the mob wants to get before firing, how long it aims, and how many shots it fires per burst.

BP/entities/custom_archer.json
{
  "format_version": "1.20.80",
  "minecraft:entity": {
    "description": {
      "identifier": "wiki:custom_archer",
      "is_spawnable": true,
      "is_summonable": true
    },
    "components": {
      "minecraft:shooter": {
        "def": "minecraft:arrow"
      },
      "minecraft:behavior.ranged_attack": {
        "priority": 3,
        "attack_interval_min": 1.0,
        "attack_interval_max": 3.0,
        "attack_radius": 15.0,
        "burst_shots": 1,
        "burst_interval": 0.0,
        "speed_multiplier": 1.0
      }
    }
  }
}

Knockback Roars and Area Attacks

For bosses or heavy mobs that need to clear space around themselves, "minecraft:behavior.knockback_roar" provides a built-in radial attack that damages and throws back nearby entities without spawning projectiles. It triggers automatically on a cooldown whenever the mob has an active target within range.

You can filter which entities take damage and which take knockback independently using standard entity filter syntax. This is useful for preventing a boss from accidentally knocking back or killing its own summoned minions during a fight.

BP/entities/boss_roarer.json
{
  "format_version": "1.20.80",
  "minecraft:entity": {
    "description": {
      "identifier": "wiki:boss_roarer",
      "is_spawnable": true,
      "is_summonable": true
    },
    "components": {
      "minecraft:behavior.knockback_roar": {
        "priority": 1,
        "duration": 1.0,
        "attack_time": 0.5,
        "knockback_damage": 6,
        "knockback_horizontal_strength": 4,
        "knockback_vertical_strength": 2,
        "knockback_range": 6,
        "cooldown_time": 10.0,
        "on_roar_end": {
          "event": "wiki:roar_finished"
        }
      }
    }
  }
}

Which versions this applies to

Applies to Minecraft Bedrock 1.16.0 and newer (examples use format_version 1.20.80). All components shown are stable and do not require any experimental toggles.

When it does not work

What you seeWhyThe fix
The entity walks right up to the player and pushes them around, but never deals any damage.You included "minecraft:behavior.melee_attack" and a targeting goal, but forgot to add the "minecraft:attack" component to define the damage value (or set its damage to 0).Add "minecraft:attack": { "damage": 4 } inside the entity's "components" block.
The entity never aggros onto players or other mobs, even when attacked in Survival mode.Attack behaviors like "minecraft:behavior.melee_attack" or "minecraft:behavior.ranged_attack" cannot pick targets on their own.Add "minecraft:behavior.nearest_attackable_target" or "minecraft:behavior.hurt_by_target" to the entity, and ensure the target's type family matches your filter.
The entity has a ranged attack behavior and aims at the player, but no projectile ever spawns.The "minecraft:shooter" component is missing, or the projectile identifier in its "def" property is misspelled or lacks a "minecraft:projectile" component of its own.Add "minecraft:shooter" alongside "minecraft:behavior.ranged_attack" and test with a known vanilla projectile like "minecraft:arrow" first.
The mob stops chasing the player after walking only a few blocks away, even though max_dist on the target goal is high.The entity's overall "minecraft:follow_range" component defaults to a smaller radius than your targeting goal's "max_dist", capping how far the AI can maintain a target.Add "minecraft:follow_range" to the entity's components and set its "value" and "max" to at least match the "max_dist" in your targeting behavior.

Reference, straight from the game files

Read out of the game itself, so the ids match the version you are building for.