# rmp::behavior::Hitbox

> What hurts: a sword's swing, a spike, a bullet, an explosion.

Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Hitbox.html

behavior `#include <rmp/behavior.h>` [include/rmp/behavior.h:593](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L593-L618)

struct Hitbox

What hurts: a sword's swing, a spike, a bullet, an explosion. On touching an object with an [`rmp::behavior::Health`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html) on one of the layers it `hits`, it calls that Health's `damage()` — the invulnerable window, on_damage and the once-only death all apply — and pushes it away. A Health's `hurt_by` does not count an object with a Hitbox: the Hitbox is what decides, so nothing is hurt twice for one touch.

From the editor: "damage" (Int), "knockback" (Float).

Added to an object with `add<rmp::behavior::Hitbox>()`; the framework calls its `_update`, `_collision` with the object it is on.

## Fields

| Field | Type | Default | What it is |
|---|---|---|---|
| `damage` | `int` | `1` | What one hit costs |
| `hits` | `unsigned` | `0xFFFFFFFFu` | The layers it hurts; the collision layers decide who it touches |
| `knockback` | `float` | `0` | The impulse that pushes the one hit away from it |
| `destroy_on_hit` | `bool` | `false` | Discarded after its first hit, landed or not: a bullet |
| `once_per_target` | `bool` | `false` | Hits each object once at most: a sword's one swing |
| `on_hit` | `Callback<Object &, Object &>` |  | (the hitbox, who it hurt), when the damage landed |
| `ours` | `struct { … }` |  | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. |

### `from`

static Hitbox from(const MapObject &object)

static function [include/rmp/behavior.h:605](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L605)

A Hitbox with the fields the map's entity has by these names — damage, knockback — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file.
