Multi-hit processing script (※ quite complex!)

I created a multi-hit processing script.

When the attack judgment is active, setting ActivatedSkillId in VariableSettings allows the script to automatically perform hit judgments for the corresponding skill based on the skill data configured in the database, executing independent hit control for each enemy.

Judgments are performed every HitInterval (frames), with a maximum of HitCount hits.

If HitJudgeMode is set to 0 in the database, a hit judgment occurs every time contact is made with the target. If set to 1, the judgment continues as long as contact is maintained.

Once a hit judgment occurs, signals can be emitted and other actions can be taken, so feel free to write your own custom logic!

As a piece of trivia, signals sent via the script in VS (Visual Studio) require the data type of the sent value to match the receiver’s expected type for the signal to trigger.

Hit judgments can be reset using reset_ methods.

HitCounter.gd (4.5 KB)
SkillList.csv (967 bytes)

This script is designed to be attached to an AttackArea2D node to emit a signal upon contact with a target.

Even if contact occurs multiple times, the processing is handled based on the hit count and cooldown (interval) for each skill.


:wrench: [Setup Instructions]

① Node Structure

Assume a Player character with the following node structure as an example:

Player (CharacterBody2D)
├── AttackArea2D ← Attach this script to this node

② Script Attachment

Attach the following script (the one just completed) to the AttackArea2D node:

extends Area2D

# (Omitted: Attach the full script from above)

③ Inspector Settings

Configure the AttackArea2D node in the Inspector as follows:

  • target_group"Enemy" (The group name of the contact target)
  • variable_settings → Reference ../VariableSettings

④ Setup for Contact Target

Prepare a signal on the enemy character side (e.g., Enemy).


[Operation Flow]

  1. AttackArea2D comes into contact with a node in the Enemy group.
  2. Retrieve the current skill ID from VariableSettings (You must set the skill ID to ActivatedSkillId during the attack).
  3. Read the HitCount and HitInterval configured for the skill via GameManager.get_project_database_plain(...).
  4. Determine whether a hit judgment is permissible based on the history recorded in hit_registry.
  5. If valid:
    • Increment the hit count.
    • Emit the attacked signal of the target node using emit_signal().
2 Likes