[Tech Share] Creating a Shield Feature with VS

c758ace774ecbfda595f4b8d15a5e861
(Note: The previous post with the same name had a technical flaw, so please refer to this post directly. The previous post has already been recommended for deletion by the moderators. Carefully observe this recorded animation: in the previous post, both the shield and HP decreased simultaneously. In this post, only the number above the hero’s head (the shield value) decreases initially, and HP only starts decreasing after the shield value reaches 0.)

  1. The Concept Behind AGM’s Automatic HP Deduction:
    (1) I previously mistakenly believed that using other attack hit conditions could interrupt this automatic damage function. This turned out to be incorrect. As long as AGM’s hitboxes are enabled and properly mapped to their corresponding attack relationships, the calculation is automatic, and VS cannot interrupt it. The only way to stop it would be to disable the hitboxes, but if hitboxes are disabled, all hit reactions become invalid, rendering the shield function useless as well.
    (2) Since we cannot stop the automatic detection of the hitboxes, how do we implement the logic to deduct from the shield when it exists, and from HP when it doesn’t? I eventually found the answer—controlling the damage rate!


    In the BaseSettings properties, there is a parameter called “taken damage rate.” Setting this to 0% means taking no damage, while setting it to 100% means taking full damage. By using this parameter to control hit reactions, we can achieve the desired effect!

  2. Specific Implementation:


    (1) Create two hitbox collision areas: one for the hero’s main body and one for the shield. Also, set up a variable named “Shield.”

    (2) In the VS script, after activating the standby state, set the condition: when Shield > 0, execute the following actions: [1. Set damage rate to 0%; 2. Enable the shield hitbox; 3. Disable the main body hitbox]. This effectively blocks AGM’s automatic collision-based HP deduction.
    (3) When a collision occurs, deduct from the shield value and run a 0.5-second loop.
    (4) When the shield value <= 0, execute the following actions: [1. Set damage rate to 100%; 2. Disable the shield hitbox; 3. Enable the main body hitbox].
    (5) You can further configure this action to play a sound effect via a 0.5-second loop triggered after a hit is registered. Additionally, set a 0.5-second invincibility period in the object’s BaseSettings.
    (6) No other operations are needed. With this setup, once the shield is depleted, AGM will automatically calculate and deduct HP damage.

1 Like