This video was cut in to two pieces because of its length. First part describes how to create Health component which is then used in second part where I create HitBox and HurtBox components. Because of that I prepared two separated sections, one for each part. However I was creating this using one project, that’s why there is only one download section with final project from 2nd part of video. Parts of code are available for free for everyone, without login.
Health component
In this tutorial, I guide you through creating a modular health system with temporary immortality in Godot. Discover the essential role of a well-designed health system, responsible for managing player vitality, damage effects, and recovery mechanisms. Gain insights into building a foundation that ensures a dynamic and engaging gaming experience. Stay tuned for the next part, where we explore hitboxes and hurtboxes components for even more advanced gameplay mechanics.
class_name Health
extends Node
signal max_health_changed(diff: int)
signal health_changed(diff: int)
signal health_depleted
@export var max_health: int = 3 : set = set_max_health, get = get_max_health
@export var immortality: bool = false : set = set_immortality, get = get_immortality
var immortality_timer: Timer = null
@onready var health: int = max_health : set = set_health, get = get_health
func set_max_health(value: int):
var clamped_value = 1 if value <= 0 else value
if not clamped_value == max_health:
var difference = clamped_value - max_health
max_health = value
max_health_changed.emit(difference)
if health > max_health:
health = max_health
func get_max_health() -> int:
return max_health
func set_immortality(value: bool):
immortality = value
func get_immortality() -> bool:
return immortality
func set_temporary_immortality(time: float):
if immortality_timer == null:
immortality_timer = Timer.new()
immortality_timer.one_shot = true
add_child(immortality_timer)
if immortality_timer.timeout.is_connected(set_immortality):
immortality_timer.timeout.disconnect(set_immortality)
immortality_timer.set_wait_time(time)
immortality_timer.timeout.connect(set_immortality.bind(false))
immortality = true
immortality_timer.start()
func set_health(value: int):
if value < health and immortality:
return
var clamped_value = clampi(value, 0, max_health)
if clamped_value != health:
var difference = clamped_value - health
health = value
health_changed.emit(difference)
if health == 0:
health_depleted.emit()
func get_health():
return health
HitBox and HurtBox components
In this sequel, I leverage the modular health system created in the previous tutorial and guide you through implementing hitboxes and hurtboxes in #Godot. We will use Health System created in last video so be sure to check it first. You can also use your own health system with this tutorial.
25 years old Indie Game Developer from Poland 🇵🇱 Creator of “Astro Strike – Space Shooter” game 👾 and “Blaze Builder – Easy Multiplatform Build” Unity tool 🎮 I create cool game dev-related projects 💻 and YouTube videos 🎬 I like emojis 😄
We use technologies like cookies to store and/or access device information. We do this to improve browsing experience and to show (non-) personalized ads. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Leave a Reply