From cedce3eef8f4392d1732ed667cfde07fa82859b1 Mon Sep 17 00:00:00 2001 From: teatov Date: Thu, 27 Feb 2025 04:00:47 +1000 Subject: [PATCH] make separate player attack effect class --- scenes/player.tscn | 25 +++++++++++++--------- scripts/effects/player_attack_effect.gd | 26 +++++++++++++++++++++++ scripts/player/player_animator.gd | 2 +- scripts/player/player_attack.gd | 28 ++++++------------------- 4 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 scripts/effects/player_attack_effect.gd diff --git a/scenes/player.tscn b/scenes/player.tscn index 9c1424d..a29f3e9 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=31 format=3 uid="uid://b73y71y3efmv"] +[gd_scene load_steps=32 format=3 uid="uid://b73y71y3efmv"] [ext_resource type="Script" path="res://scripts/player/player.gd" id="1_xt3i8"] [ext_resource type="Material" uid="uid://cc18ee0wbfoud" path="res://resources/materials/debug/debug_player.tres" id="2_0p422"] @@ -11,6 +11,7 @@ [ext_resource type="Script" path="res://scripts/effects/bone_to_flatten.gd" id="6_cumn2"] [ext_resource type="Script" path="res://scripts/effects/bone_flattener.gd" id="6_iug5b"] [ext_resource type="PackedScene" uid="uid://c8gqrealje3o" path="res://scenes/effects/shadow_decal.tscn" id="9_vgb3d"] +[ext_resource type="Script" path="res://scripts/effects/player_attack_effect.gd" id="11_1cf3j"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_tes4q"] animation = &"+idle_L" @@ -135,7 +136,7 @@ bones/45/scale = Vector3(1, 1, 1) bones/46/rotation = Quaternion(-0.0181733, 2.38379e-07, 1.14098e-08, 0.999835) bones/47/rotation = Quaternion(-1.20807e-07, 0.993087, -0.117383, 7.85287e-07) bones/49/rotation = Quaternion(-0.034235, -3.57418e-07, 8.86969e-08, 0.999414) -bones/50/rotation = Quaternion(0.0873136, -0.701695, -0.701695, -0.0873136) +bones/50/rotation = Quaternion(0.0858328, -0.701878, -0.701878, -0.0858328) bones/51/rotation = Quaternion(0.403888, -2.98082e-07, -3.85178e-07, 0.914808) bones/51/scale = Vector3(1, 1, 1) bones/52/rotation = Quaternion(-0.512846, 3.82068e-07, 4.27952e-07, 0.858481) @@ -269,13 +270,12 @@ libraries = { "": ExtResource("5_y0ods") } -[node name="AnimationTree" type="AnimationTree" parent="." node_paths=PackedStringArray("player")] +[node name="AnimationTree" type="AnimationTree" parent="."] tree_root = SubResource("AnimationNodeBlendTree_f4bn3") anim_player = NodePath("../OverrideAnimationPlayer") parameters/StateMachine/conditions/side_L = false parameters/StateMachine/conditions/side_R = false script = ExtResource("4_adlgp") -player = NodePath("..") [node name="BoneFlattener" type="Node3D" parent="." node_paths=PackedStringArray("skeleton")] script = ExtResource("6_iug5b") @@ -309,13 +309,18 @@ _collision_debug_material = ExtResource("4_ll2ct") [node name="AttackShape" type="CollisionShape3D" parent="Attack"] shape = SubResource("CylinderShape3D_qsqht") -[node name="SwoopMesh" type="MeshInstance3D" parent="Attack"] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -0.0985078, 0, 1, -4.30591e-09, 0, 0, 0) -visible = false -material_override = SubResource("StandardMaterial3D_m1xj5") -mesh = SubResource("SphereMesh_kqbjh") +[node name="Effects" type="Node3D" parent="."] -[node name="ShadowDecal" parent="." instance=ExtResource("9_vgb3d")] +[node name="ShadowDecal" parent="Effects" instance=ExtResource("9_vgb3d")] size = Vector3(1.5, 6, 1.5) +[node name="SwoopMesh" type="MeshInstance3D" parent="Effects"] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -0.0985078, 0, 1, -4.30591e-09, 0, 1, 0) +visible = false +material_override = SubResource("StandardMaterial3D_m1xj5") +cast_shadow = 0 +mesh = SubResource("SphereMesh_kqbjh") +skeleton = NodePath("../../Attack") +script = ExtResource("11_1cf3j") + [editable path="Model"] diff --git a/scripts/effects/player_attack_effect.gd b/scripts/effects/player_attack_effect.gd new file mode 100644 index 0000000..cb3710c --- /dev/null +++ b/scripts/effects/player_attack_effect.gd @@ -0,0 +1,26 @@ +extends MeshInstance3D + +@export var _swoop_effect_time: float = 0.25 + +var _swoop_effect_timer: float + +@onready var _attack: PlayerAttack = $"../../Attack" as PlayerAttack + +func _ready() -> void: + mesh.radius = _attack.attack_radius + mesh.height = _attack.attack_radius + _attack.attacked.connect(_on_attack_attacked) + + +func _process(delta: float) -> void: + if _swoop_effect_timer > 0: + _swoop_effect_timer -= delta + + (material_override as StandardMaterial3D).albedo_color = Color( + 1, 1, 1, _swoop_effect_timer / _swoop_effect_time + ) + visible = _swoop_effect_timer > 0 + + +func _on_attack_attacked() -> void: + _swoop_effect_timer = _swoop_effect_time diff --git a/scripts/player/player_animator.gd b/scripts/player/player_animator.gd index 6bfc0ff..a6f1055 100644 --- a/scripts/player/player_animator.gd +++ b/scripts/player/player_animator.gd @@ -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: diff --git a/scripts/player/player_attack.gd b/scripts/player/player_attack.gd index c142c11..90ca8af 100644 --- a/scripts/player/player_attack.gd +++ b/scripts/player/player_attack.gd @@ -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: