SCRMaps
/
Sign in

Damage and projectiles of your own

Better to make the game deal the damage than to subtract it yourself - and fast projectiles have a famous trap in their hit detection.

8 min read

The usual way to make a skill deal damage is not to subtract hit points but to spawn an invisible attacker and have it attack. Armour, upgrades and overkill then all go through the engine's own path - compute the damage yourself and you have to rebuild every one of them.

  1. 1Create an invisible attacker and an invisible target marker.
  2. 2Give the attacker's weapon splash, and the area damage is computed for you.
  3. 3Order the attack, and scale the damage by repeating it.

Give each projectile a hit cooldown. Without one, a projectile standing in a crowd deals its damage every trigger cycle. This is not optional.

Set the attacker weapon's firing angle to 255. Leave it at the stock value and the attacker spends cycles turning to face the target, and its removal timer expires before it ever fires. Nothing happens, and nothing shows you why.

And if your function creates a unit, check there is a free slot before it does. With all 1,700 unit slots full, the "next unit to be created" pointer reads 0, and following that 0 is not a harmless no-op - it is an EUD error. This matters more in a library function, because the caller has no idea the map is at the cap.

A projectile that is a unit has to test for collisions itself, and there is a bug here that looks like physics. Single shots are accurate; rapid fire passes straight through.

The cause is not tunnelling, it is a cache. A per-projectile loop that moves a location onto the bullet and Brings it computes the count once and hands every later bullet the first one's answer, because editing a location's coordinates by EUD does not invalidate the Bring cache. So if the first bullet misses they all miss. One line inside the loop that invalidates the cache fixes it.

The other three
Negate AtMost 0 rather than using AtLeast 1Bring AtLeast 1 only sees completed units, so an egg or a building under construction is not a collision.
Do not write hit boxes by handThere are helpers to put a location on a unit's centre and to grow it on each axis. Writing the four bounds by hand means remembering to clamp at 0, which most forget.
Raise the new-unit loop's argumentThe new-unit iterator stops after a number of consecutive already-known units, defaulting to two. A projectile system creating several a cycle misses new ones unless you raise it.
Counting units lags a cycle