[Tech Share] Achieving a

d1f72d8e5bc72ffb4e320b593f7dd948

1 Feature I want to implement: Create a skill where, when the hero acquires a [Shield] skill, this shield can block one instance of damage. The shield has durability ranging from 1 to 3. When the shield’s durability breaks down to 0, the hero takes damage again.

2 I took many detours, believing that this logic required complex operations. I tried using GD code, attempted to create an independent hitbox for the shield, or create a new shield object to calculate damage separately, and even tried toggling the collision box state. After 3 days of attempts and thinking, I surprisingly discovered that by leveraging AGM’s powerful automatic damage mechanism, a single operation could achieve these seemingly complex ideas.

3 Let’s first explain the principle. AGM’s automatic damage detection, combined with AGM’s unique hitbox, essentially implements an “any state” or per-frame attack detection function. This means that no matter what action you are performing, as long as you get hit, it automatically triggers automatic damage reduction and health loss. (And it does not conflict with any other actions.) Meanwhile, if you manually use VS for hit condition actions, this automatic hit detection will become inactive, giving way to your manual operations. And if your manual operation conditions are not triggered, this automatic hit detection will automatically turn on and function. (This mechanism is simply a stroke of genius! :smiling_face_with_three_hearts:)

4 Directly showing the result:
(1) You only need to create a shield variable, say 3, and then write an action condition: When [Shield] > 0, upon being hit, reduce Shield by 1. (That’s it, it’s that simple, that straightforward!!! No extra operations needed.)
(2) When the shield is greater than 0, AGM will prioritize executing the shield minus one operation and will not execute automatic health loss. When the shield is 0, automatic damage immediately resumes functioning!
(3) If you want the shield to have a cooldown, you can add a 0.5-second loop operation when the shield is hit.


Actually, my VS design is not yet perfect. Although this achieves a seamless switch between the shield and automatic damage reduction, in actual runtime, the inner loop of shield -1 does not break, and the shield will continue to decrease after = 0. However, this is not a major issue, and it is already sufficient to perfectly implement the function. It can be optimized later.

Summary: “True skill appears clumsy, true wisdom appears foolish.” In my year of using AGM, I have always seen too many users complaining that AGM’s operations are unreasonable, cumbersome, and not clever enough. This time, after deeply studying a principle of AGM, I deeply felt its convenience and ease of use. I want to praise AGM here; this design is truly amazing!

2 Likes

One more thing to add: when the hitbox of your shield does not match the hitbox of the hero’s body (for example, when the shield’s hitbox is larger than the body’s), you need to create an additional hitbox and manually configure which hitbox is used for damage detection. Then, when the shield reaches 0, you must reconfigure which hitbox is used for damage detection.