add attack cooldown and hit window

This commit is contained in:
Teatov 2025-02-25 00:47:40 +10:00
parent 2da0820964
commit 20517af12e
3 changed files with 46 additions and 4 deletions

View File

@ -10,7 +10,7 @@
height = 1.8
[sub_resource type="CylinderShape3D" id="CylinderShape3D_qsqht"]
height = 0.43
height = 0.5
radius = 2.0
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_m1xj5"]

View File

@ -3,6 +3,8 @@ extends RefCounted
const MARGIN = 0.01
var is_visible: bool = true
var _mesh_nodes: Array[MeshInstance3D] = []
@ -56,6 +58,12 @@ func init(children: Array[Node], parent: Node, material: Material) -> void:
Debugger.mode_changed.connect(_on_debugger_mode_changed)
func set_visibility(visible: bool) -> void:
is_visible = visible
for node in _mesh_nodes:
node.visible = is_visible
func _on_debugger_mode_changed(mode: Debugger.Mode) -> void:
for mesh_node in _mesh_nodes:
mesh_node.visible = mode == Debugger.Mode.FULL

View File

@ -3,6 +3,8 @@ extends Area3D
signal attacked
const COOLDOWN_TIME: float = 0.3
const HIT_WINDOW_TIME: float = 0.25
const SWOOP_EFFECT_TIME: float = 0.25
@export var _collision_debug_material: Material
@ -10,6 +12,8 @@ const SWOOP_EFFECT_TIME: float = 0.25
var _debug_collision_shapes := DebugCollisionShapes.new()
var _cooldown_timer: float
var _hit_window_timer: float
var _swoop_effect_timer: float
@onready var _swoop_mesh: MeshInstance3D = $SwoopMesh
@ -29,23 +33,50 @@ func _unhandled_input(event: InputEvent) -> void:
func _process(delta: float) -> void:
if _swoop_effect_timer >= 0:
if _cooldown_timer > 0:
_cooldown_timer -= delta
if _hit_window_timer > 0:
_hit_window_timer -= delta
elif _debug_collision_shapes.is_visible:
_debug_collision_shapes.set_visibility(false)
if _swoop_effect_timer > 0:
_swoop_effect_timer -= delta
else:
_swoop_effect_timer = 0
(_swoop_mesh.material_override as StandardMaterial3D).albedo_color = Color(
1, 1, 1, _swoop_effect_timer / SWOOP_EFFECT_TIME
)
_swoop_mesh.visible = _swoop_effect_timer > 0
Debugger.text("_cooldown_timer", _cooldown_timer, 2)
Debugger.text("_hit_window_timer", _hit_window_timer, 2)
Debugger.text("_swoop_effect_timer", _swoop_effect_timer, 2)
Debugger.vector(
"fghdh",
global_position,
global_position + global_basis.z.rotated(Vector3.UP, _attack_max_angle) * 2
)
Debugger.vector(
"fghdh2",
global_position,
global_position + global_basis.z.rotated(Vector3.UP, -_attack_max_angle) * 2
)
func _physics_process(_delta: float) -> void:
monitoring = Input.is_action_just_pressed("attack")
func _attack() -> void:
if _cooldown_timer > 0:
return
attacked.emit()
_cooldown_timer = COOLDOWN_TIME
_hit_window_timer = HIT_WINDOW_TIME
_swoop_effect_timer = SWOOP_EFFECT_TIME
_debug_collision_shapes.set_visibility(true)
func _hit_projectile(projectile: Projectile) -> void:
@ -60,5 +91,8 @@ func _hit_projectile(projectile: Projectile) -> void:
func _on_body_entered(node: Node3D) -> void:
if _hit_window_timer <= 0:
return
if node is Projectile:
_hit_projectile(node as Projectile)