Kill Unit

From LuaSTG Wiki
Jump to navigation Jump to search

A kill unit node marks an object to be killed at the end of a frame.


Objects on Kill[edit | edit source]

After an object is created in LuaSTG, it can be removed from the game from either deletion (see Delete Unit) or a kill, where the kill is performed by a kill unit node.

Different from delete unit, kill unit does not trigger on del method of the object. In replacement, it will trigger on kill, which usually does some slightly different things. As an example, a bullet that is killed will drop a faith point by default, instead of playing the deletion effect.


Parameters[edit | edit source]

This is list of parameters of kill unit node.

Parameters Function
Target (LuaSTG object) The object to be killed
Trigger Event (Boolean) Whether or not to trigger the kill event of the object

If Trigger Event parameter is set to true, the unit will execute its on kill method before its final deletion at the end of the frame.


Example of Use[edit | edit source]

Here we look at an example of applying the kill node on player bullets (bullets shot by the player).

Kill Unit Example 1.png

All bullets fired by the player will be killed when the non-spell starts. Shortly after the start of the game, the player bullets on the screen are all cleared at one frame, leaving bullet deletion effects on the screen for a short time.

Notice the difference between killing enemy bullets (which you can try by spawning some bullets and replacing GROUP_PLAYER_BULLET with GROUP_ENEMY_BULLET) and player bullets. When the enemy bullets are killed, faith points will be spawned by default. However, the player bullets only leaves some deletion effect on the screen.

On the opposite, if player bullets are deleted but not killed, they will leave no deletion effects at all, regardless of whether Trigger Event is set.

Equivalent Code[edit | edit source]

Upon running the script, the kill unit node will be translated to something like "_kill(unit, true)", where unit is the object to be killed. A similar alternative to write this in code is to use Kill(unit, true).