From 48c56c3d1a50c6c953ba81fc024c82d072e505ea Mon Sep 17 00:00:00 2001 From: Just Dzhi Date: Sun, 1 Oct 2023 00:32:56 +0400 Subject: [PATCH] Bat --- src/models/enemies/bat/Bat.tscn | 4 +++- src/models/enemies/bat/bat.gd | 17 ++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/models/enemies/bat/Bat.tscn b/src/models/enemies/bat/Bat.tscn index 8379ea4..8d8df04 100644 --- a/src/models/enemies/bat/Bat.tscn +++ b/src/models/enemies/bat/Bat.tscn @@ -13,6 +13,8 @@ script = ExtResource( 2 ) texture = ExtResource( 1 ) centered = false -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] position = Vector2( 7, 4 ) shape = SubResource( 1 ) diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd index acb41bf..48d14f2 100644 --- a/src/models/enemies/bat/bat.gd +++ b/src/models/enemies/bat/bat.gd @@ -1,26 +1,25 @@ extends KinematicBody2D var velocity = Vector2.ZERO -var speed = 48 +var speed = 64 func _process(_delta): get_node("Sprite").flip_h = true if $"../Player".global_position.x > self.position.x else false func _physics_process(_delta): - if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) > 48: + if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) > 64: velocity.x = speed * cos(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8))) velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8))) else: velocity = Vector2.ZERO - if abs($"../Player".velocity.x) > 0 and position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 48: - velocity.x = speed * 2 * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) - velocity.y = speed * 2 * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) + if abs($"../Player".velocity.x) > 0 and position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 64: + velocity.x = speed * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) + velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) - if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 32: - velocity.x = speed * 2 * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) - velocity.y = speed * 2 * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) + if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 48: + velocity.x = speed * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) + velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) move_and_slide(velocity) -