Open BaseSettings, set both HP and Max HP to 20, and set Blink Duration to 0.1 seconds. This makes it easier to notice invincibility by adding a blinking effect.
While TakenDamageSettings allows many configurations, we’ll use it this time just to add a damage voice.
Create a new damage setting, enable Play Sound in Other Settings, and set the sound to male_1_1_A.
Test the game. The player should now blink and play a voice when taking damage. However, the player and zombies are pushing each other, so let’s fix that.
Select the Player node and change its Collision > Collision Layer from 1 to 2.
Layers define what physics layer the object belongs to, while Masks define which layers it collides with.
Zombies use Layer 2 / Mask 1, so by putting the player on Layer 2, they will no longer collide with each other.
7.(CollisionLayer/CollisionMask is explained in more detail in a separate manual.)*
You now have a character with 20 HP, who becomes invincible for 1 second after taking 1 point of damage from an enemy.
Notes
What you can do with TakenDamageSettings
You can configure things like damage multipliers based on attack attributes set in Attack Settings. This is useful for setting up weaknesses and resistances.
You can also configure hit stop, such as making the game temporarily slow down when receiving a heavy blow.
Configure the ImageGauge properties as follows:
Set the Current Value to sampleplayer.hp and the Max Value to sampleplayer.max_hp.
The Object_Sampleplayer.tscn is located in the sampleobject folder.
Next, configure the properties of TextureProgressBar within the ImageGauge.
Enable Nine Patch Stretch, and set Left Limit and Right Limit to 10px.
This allows resizing without distorting the bar’s proportions.
Test the game.
If set correctly, the HP will be displayed as a white bar and will decrease when hit by a zombie.
Now let’s add a frame.
Add a new node under ImageGauge: NinePatchRect.
This node creates a rectangle that stretches while maintaining proportions, using Nine Patch settings.
Bar Types
By changing the Fill Mode of the ImageGauge, you can create various types of bars—including vertical and circular gauges.
You can also change the bar’s color using the Tint property.
About Nine Patch
Nine Patch is a technique that divides an image into 9 sections and stretches them proportionally to avoid distortion.
This method is also useful for things like message windows.