]> purplebirdman git - frog-ninja.git/blob - asset/character/model/hitbox.gd
Squashed commit of the following:
[frog-ninja.git] / asset / character / model / hitbox.gd
1 extends Area3D
2 class_name Hitbox
3
4
5 @export var debug_color_hit: Color = Color(Color.YELLOW, 0.5)
6 @export var debug_color_standby: Color = Color(Color.GREEN, 0.5)
7
8 @onready var shape: CollisionShape3D = $CollisionShape3D
9 @onready var hit_effect: HitEffect = $HitEffect
10
11 var _last_hit: float = 0
12
13
14 func _ready() -> void:
15         shape.debug_color = debug_color_standby
16
17
18 func _process(delta: float) -> void:
19         if monitoring:
20                 for area in get_overlapping_areas():
21                         if area is Hurtbox:
22                                 on_hit(area)
23                 
24         _last_hit += delta
25         if _last_hit > 1.0:
26                 shape.debug_color = debug_color_standby
27
28
29 func on_hit(area: Hurtbox):
30         if is_being_attacked_by(area):
31                 _last_hit = 0
32                 shape.debug_color = debug_color_hit
33                 hit_effect.trigger()
34                 
35                 area.ignore_list.append(self)
36                 on_successful_hit(area)
37
38
39 func is_being_attacked_by(area: Hurtbox):
40         return area.is_attacking and not area.ignore_list.has(self)
41
42
43 ## To be overridden by a child class
44 func on_successful_hit(_area: Hurtbox):
45         pass