API Docs for:
Show:

Attacking Class

A component class responsible for attacking.

Constructor

Attacking

(
  • attack
  • rightAttackPointX
  • rightAttackPointY
  • rightAttackDirectionX
  • rightAttackDirectionY
  • attackCooldown
  • foeCollideWith
)

Parameters:

  • attack MeleeAttack | RangedAttack

    An object describing the type of attack the entity will perform.

  • rightAttackPointX Number

    The x component of the attack point. The attack point is a position relative to the entity's position from which an attack will be performed. For melee attacks, it's the center point for the scan shape, for ranged attacks it's the point from which projectiles will be fired. This point is for when an entity attacks while facing to the right, the left variant is calculated automatically.

  • rightAttackPointY Number

    The y component of the attack point. The attack point is a position relative to the entity's position from which an attack will be performed. For melee attacks, it's the center point for the scan shape, for ranged attacks it's the point from which projectiles will be fired. This point is for when an entity attacks while facing to the right, the left variant is calculated automatically.

  • rightAttackDirectionX Number

    The x component of the direction vector. The vector should be pointing in the attack direction when an entity is facing to the right, the left variant is calculated automatically. This vector needs to be normalized. A direction is only required if the attack type is ranged.

  • rightAttackDirectionY Number

    The y component of the direction vector. The vector should be pointing in the attack direction when an entity is facing to the right, the left variant is calculated automatically. This vector needs to be normalized. A direction is only required if the attack type is ranged.

  • attackCooldown Number

    Attack cooldown needs to be in seconds.

  • foeCollideWith Number

    A bit mask used when querying the physics engine for enemy entities.

Methods

canAttack

() Boolean

Check whether the entity is ready to attack.

Returns:

Boolean:

getAttack

() MeleeAttack | RangedAttack

Returns the attack object.

getAttackCooldown

() Number

Returns the attack cooldown.

Returns:

Number: Attack cooldown is in seconds.

getAttackCooldownRemaining

() Number

Returns the remaining attack cooldown.

Returns:

Number: Number of seconds remaining before the entity can attack again.

getFoeCollideWith

() Number

Returns:

Number:

getRightAttackDirection

(
  • vector
)

Parameters:

  • vector Vector2D

    Vector to which the attack direction will be copied.

getRightAttackPoint

(
  • vector
)

Parameters:

  • vector Vector2D

    Vector to which the attack point will be copied.

setFoeCollideWith

(
  • foeCollideWith
)

Parameters:

  • foeCollideWith Number

    A bit mask used when querying the physics engine for enemy entities.

setRightAttackDirection

(
  • x
  • y
)

Parameters:

  • x Number

    The x component of the direction vector. The vector should be pointing in the attack direction when an entity is facing to the right, the left variant is calculated automatically. This vector needs to be normalized. A direction is only required if the attack type is ranged.

  • y Number

    The y component of the direction vector. The vector should be pointing in the attack direction when an entity is facing to the right, the left variant is calculated automatically. This vector needs to be normalized. A direction is only required if the attack type is ranged.

setRightAttackPoint

(
  • x
  • y
)

Parameters:

  • x Number

    The x component of the attack point. The attack point is a position relative to the entity's position from which an attack will be performed. For melee attacks, it's the center point for the scan shape, for ranged attacks it's the point from which projectiles will be fired. This point is for when an entity attacks while facing to the right, the left variant is calculated automatically.

  • y Number

    The y component of the attack point. The attack point is a position relative to the entity's position from which an attack will be performed. For melee attacks, it's the center point for the scan shape, for ranged attacks it's the point from which projectiles will be fired. This point is for when an entity attacks while facing to the right, the left variant is calculated automatically.