make separate player attack effect class
This commit is contained in:
@@ -3,7 +3,7 @@ extends AnimationTree
|
||||
const SUFFIX_LEFT := "_L"
|
||||
const SUFFIX_RIGHT := "_R"
|
||||
|
||||
@export var player: Player
|
||||
@onready var player: Player = $"../" as Player
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
||||
@@ -8,12 +8,11 @@ enum Side { RIGHT, LEFT }
|
||||
@export_group("Collision")
|
||||
@export var _collision_debug_material: Material
|
||||
@export var _attack_max_angle: float = 2 * PI / 3
|
||||
@export var _attack_radius: float = 2
|
||||
@export var attack_radius: float = 2
|
||||
|
||||
@export_group("Timers")
|
||||
@export var _cooldown_time: float = 0.3
|
||||
@export var _hit_window_time: float = 0.15
|
||||
@export var _swoop_effect_time: float = 0.25
|
||||
|
||||
@export_group("Hits")
|
||||
@export var _hit_projectile_speed: float = 35
|
||||
@@ -25,13 +24,10 @@ var _debug_collision_shapes := DebugCollisionShapes.new()
|
||||
|
||||
var _cooldown_timer: float
|
||||
var _hit_window_timer: float
|
||||
var _swoop_effect_timer: float
|
||||
|
||||
@onready var _attack_shape_node: CollisionShape3D = $AttackShape
|
||||
@onready var _swoop_mesh_node: MeshInstance3D = $SwoopMesh
|
||||
|
||||
@onready var _attack_shape: CylinderShape3D = _attack_shape_node.shape as CylinderShape3D
|
||||
@onready var _swoop_mesh: SphereMesh = _swoop_mesh_node.mesh as SphereMesh
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -40,7 +36,7 @@ func _ready() -> void:
|
||||
area_entered.connect(_on_area_entered)
|
||||
|
||||
position.y = Projectile.HEIGHT
|
||||
_set_collision_size(_attack_radius)
|
||||
_set_collision_size(attack_radius)
|
||||
|
||||
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
|
||||
|
||||
@@ -59,23 +55,14 @@ func _process(delta: float) -> void:
|
||||
elif _debug_collision_shapes.is_visible:
|
||||
_debug_collision_shapes.set_visibility(false)
|
||||
|
||||
if _swoop_effect_timer > 0:
|
||||
_swoop_effect_timer -= delta
|
||||
|
||||
(_swoop_mesh_node.material_override as StandardMaterial3D).albedo_color = Color(
|
||||
1, 1, 1, _swoop_effect_timer / _swoop_effect_time
|
||||
)
|
||||
_swoop_mesh_node.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) * _attack_radius
|
||||
+ global_basis.z.rotated(Vector3.UP, _attack_max_angle) * attack_radius
|
||||
)
|
||||
)
|
||||
Debugger.vector(
|
||||
@@ -83,7 +70,7 @@ func _process(delta: float) -> void:
|
||||
global_position,
|
||||
(
|
||||
global_position
|
||||
+ global_basis.z.rotated(Vector3.UP, -_attack_max_angle) * _attack_radius
|
||||
+ global_basis.z.rotated(Vector3.UP, -_attack_max_angle) * attack_radius
|
||||
)
|
||||
)
|
||||
for dir_angle: float in _direction_angles.keys():
|
||||
@@ -92,7 +79,7 @@ func _process(delta: float) -> void:
|
||||
global_position,
|
||||
(
|
||||
global_position
|
||||
+ global_basis.z.rotated(Vector3.UP, dir_angle) * _attack_radius
|
||||
+ global_basis.z.rotated(Vector3.UP, dir_angle) * attack_radius
|
||||
),
|
||||
Color.BLUE
|
||||
)
|
||||
@@ -110,12 +97,11 @@ 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)
|
||||
side = Side.LEFT if side == Side.RIGHT else Side.RIGHT
|
||||
attacked.emit()
|
||||
|
||||
|
||||
func _hit_projectile(projectile: Projectile) -> void:
|
||||
@@ -155,8 +141,6 @@ func _hit_projectile(projectile: Projectile) -> void:
|
||||
|
||||
func _set_collision_size(radius: float) -> void:
|
||||
_attack_shape.radius = radius
|
||||
_swoop_mesh.radius = radius
|
||||
_swoop_mesh.height = radius
|
||||
|
||||
|
||||
func _on_area_entered(node: Node3D) -> void:
|
||||
|
||||
Reference in New Issue
Block a user