add hitstop
This commit is contained in:
@@ -18,6 +18,8 @@ enum Side { RIGHT, LEFT }
|
||||
@export_group("Hits")
|
||||
@export var _hit_projectile_speed: float = 35
|
||||
@export var _direction_angles: Dictionary[float, float] = {0.0: 0.0, PI: PI / 2.0}
|
||||
@export var _hit_stop_time_scale := 0.05
|
||||
@export var _hit_stop_duration := 0.25
|
||||
|
||||
var side := Side.RIGHT
|
||||
|
||||
@@ -25,6 +27,7 @@ var _debug_collision_shapes := DebugCollisionShapes.new()
|
||||
|
||||
var _cooldown_timer: float
|
||||
var _hit_window_timer: float
|
||||
var _queue_hit_stop: bool
|
||||
|
||||
@onready var _attack_shape_node: CollisionShape3D = $AttackShape
|
||||
|
||||
@@ -51,6 +54,10 @@ func _process(delta: float) -> void:
|
||||
elif _debug_collision_shapes.is_visible:
|
||||
_debug_collision_shapes.set_visibility(false)
|
||||
|
||||
if _queue_hit_stop:
|
||||
_queue_hit_stop = false
|
||||
_hit_stop(_hit_stop_time_scale, _hit_stop_duration)
|
||||
|
||||
Debugger.text("_cooldown_timer", _cooldown_timer, 2)
|
||||
Debugger.text("_hit_window_timer", _hit_window_timer, 2)
|
||||
Debugger.vector(
|
||||
@@ -135,6 +142,7 @@ func _hit_projectile(projectile: Projectile) -> void:
|
||||
projectile.global_position + new_direction
|
||||
)
|
||||
projectile.hit(new_direction * _hit_projectile_speed)
|
||||
_queue_hit_stop = true
|
||||
break
|
||||
|
||||
prev_dir_angle = dir_angle
|
||||
@@ -144,6 +152,12 @@ func _set_collision_size(radius: float) -> void:
|
||||
_attack_shape.radius = radius
|
||||
|
||||
|
||||
func _hit_stop(time_scale: float, duration: float) -> void:
|
||||
Engine.time_scale = time_scale
|
||||
await get_tree().create_timer(time_scale * duration).timeout
|
||||
Engine.time_scale = 1
|
||||
|
||||
|
||||
func _on_area_entered(node: Node3D) -> void:
|
||||
if _hit_window_timer <= 0:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user