WeaponHitboxComponent - UQdeco2800/2021-studio-2 GitHub Wiki

WeaponHitboxComponents are the same as normal hit-boxes with a few key differences:

  1. Weapon hit-boxes can be resized at run-time. This is done by destroying & resetting the fixture.
  2. They are positioned relative to the entity, using constants defined in MeleeWeapon.java
  3. They aren't set by default, i.e. the create() function doesn't set the fixture.

Setting

Weapon hit-boxes can be set using the set() method. This method takes two parameters:

  1. size - A vector that represents the attack width & range of the weapon, as x & y components. The size is relative to the entity.
  2. direction - The direction of the hit-box, relative to the entity. Must be one of the five constants defined in MeleeWeapon.java

Example

Using the above example, this gives:

  1. Attack width = 1 (1 * entity's width)
  2. Attack range = 0.5 (0.5 * entity's height)
  3. Direction = MeleeWeapon.RIGHT

righthitbox

Destroying

Weapon hit-boxes can be destroyed simply using

Notes

  1. Although every melee weapon requires a weaponHitboxComponent on its owner entity, that relationship is not bi-directional.
    • i.e. you can have an entity that has a weaponHitboxComponent, but not a meleeWeapon. This becomes useful for things such as AOE attacks, abilities, time-activated traps/explosions, and more.

Authors

This class was written by Jacob Edwards @jac0be