HurtBoxComponent - acrimi/Raven GitHub Wiki

HurtBoxComponent defines one more hurtboxes that will be attached to an entity. Hurtboxes will take damage from any entity that has a HitBoxComponent with intersecting hitboxes. This damage is then deducted from the hp of the entity's HealthComponent. The configuration can range from single static hurtboxes to complex, orientation-aware, time-based sequences of multiple hurtboxes.

Configuration

When used inside the components block, the initial state of the component can be configured with the following parameters:

Key Type Description
yieldFactor float A scalar that will be applied to the knockback force applied by a HitBoxComponent. Defaults to 1.
multipleHitsPerFrame boolean Whether or not the component can register multiple hits in a single frame. When false the first hurtbox that takes damage will cause the rest of the hurtboxes to become disabled for the rest of the frame. Defaults to false.
boxes object[] An array of hurtbox configurations that will be applied by this component. If only one hurtbox is defined, this key can be omitted and the hurtbox configuration can be defined as the top level object, including the yieldFactor and multipleHitsPerFrame keys.
      weaknessFactor float A scalar that will be applied to the damage inflicted by a HitBoxComponent. Defaults to 1.
      whitelist int[]|int One or more hit codes that will be allowed to deal damage to this hurtbox. Any hit boxes not containing one of these hit codes will be ignored.
      blacklist int[]|int One or more hit codes that will not be allowed to deal damage to this hurtbox. Any hit boxes containing one of these hit codes will be ignored.
      mirrored boolean Whether or not the left/right sequences should be mirrored around the entity's horizontal axis when the opposite direction is missing. This can help avoid creating redundant configurations for each direction.
      sequence object[] A sequence of positions and sizes that this hurtbox will cycle through while it's attached. If this hurtbox has only one state, this key can be omitted and the configuration can be passed directly to the top level hurtbox object. This will be the default sequence for any orientations without explicit configurations.
            x float The left position of the hurtbox at this step of the sequence, relative to the entity's left position
            y float The bottom position of the hurtbox at this step of the sequence, relative to the entity's bottom position
            width float The width of the hurtbox at this step of the sequence
            height float The height of the hurtbox at this step of the sequence
            duration float The time, in seconds, that the hurtbox will be in this position before moving to the next in the sequence.
      left object[]|object A sequence of positions and sizes that this hurtbox will cycle through while it's attached and the entity is facing left. If the hurtbox has only one state in this direction, the configuration can be passed directly and the array structure can be omitted. See sequence for the supported properties.
      right object[]|object A sequence of positions and sizes that this hurtbox will cycle through while it's attached and the entity is facing right. If the hurtbox has only one state in this direction, the configuration can be passed directly and the array structure can be omitted. See sequence for the supported properties.
      down object[]|object A sequence of positions and sizes that this hurtbox will cycle through while it's attached and the entity is facing down. If the hurtbox has only one state in this direction, the configuration can be passed directly and the array structure can be omitted. See sequence for the supported properties.
      up object[]|object A sequence of positions and sizes that this hurtbox will cycle through while it's attached and the entity is facing up. If the hurtbox has only one state in this direction, the configuration can be passed directly and the array structure can be omitted. See sequence for the supported properties.

Examples:

"HurtBoxComponent": {
  "yieldFactor": 0.5,
  "multipleHitsPerFrame": true,
  "weaknessFactor": 0.5,
  "whitelist": 1,
  "blacklist": [
    2,
    3
  ],
  "x": 0,
  "y": 0,
  "width": 16,
  "height": 16
}
"HurtBoxComponent": {
  "yieldFactor": 2,
  "multipleHitsPerFrame": false,
  "weaknessFactor": 2,
  "whitelist": [
    1,
    2
  ],
  "blacklist": 3,
  "sequence": [
    {
      "x": 0,
      "y": 0,
      "width": 16,
      "height": 16,
      "duration": 0.2
    },
    {
      "x": -8,
      "y": -8,
      "width": 32,
      "height": 32,
      "duration": 0.2
    }
  ]
}
"HurtBoxComponent": {
  "mirrored": true,
  "left": [
    {
      "x": 0,
      "y": 0,
      "width": 16,
      "height": 16,
      "duration": 0.2
    },
    {
      "x": -8,
      "y": -8,
      "width": 32,
      "height": 32,
      "duration": 0.2
    }
  ],
  "up": {
    "x": 0,
    "y": 0,
    "width": 16,
    "height": 16
  },
  "down": {
    "x": 0,
    "y": 0,
    "width": 16,
    "height": 16
  }
}
"HurtBoxComponent": {
  "yieldFactor": 2,
  "multipleHitsPerFrame": false,
  "boxes": [
    {
      "weaknessFactor": 2,
      "whitelist": 1,
      "blacklist": 3,
      "x": 0,
      "y": 0,
      "width": 16,
      "height": 16
    },
    {
      "x": -8,
      "y": -8,
      "width": 32,
      "height": 32
    }
  ]
}
"HurtBoxComponent": {
  "boxes": [
    {
      "x": 0,
      "y": 0,
      "width": 16,
      "height": 16
    },
    {
      "weaknessFactor": 2,
      "whitelist": 1,
      "blacklist": 3,
      "mirrored": true,
      "sequence": [
        {
          "x": 0,
          "y": 0,
          "width": 16,
          "height": 16,
          "duration": 0.2
        },
        {
          "x": -8,
          "y": -8,
          "width": 32,
          "height": 32,
          "duration": 0.2
        }
      ],
      "left": [
        {
          "x": 0,
          "y": 0,
          "width": 16,
          "height": 16,
          "duration": 0.2
        },
        {
          "x": -8,
          "y": -8,
          "width": 32,
          "height": 32,
          "duration": 0.2
        }
      ],
      "up": {
        "x": 0,
        "y": 0,
        "width": 16,
        "height": 16
      }
    }
  ]
}

Properties

This component has no exposed properties