Fix Target Selection

main
Luna Brovchuk 2023-10-01 12:24:43 +02:00
parent fed4a0779a
commit b121e6a10d
3 changed files with 13 additions and 13 deletions

View File

@ -1,7 +1,6 @@
extends KinematicBody2D
extends EnemyClass
onready var player = $"../../Player"
var speed_multiplier = 1
var dash_target = Vector2.ZERO
var dash_timer = .0
var dashing = false
@ -13,10 +12,10 @@ func _physics_process(delta):
else:
if dash_target == Vector2.ZERO:
var angle = global_position.angle_to_point(player.global_position) + PI
dash_target = global_position + Vector2(70, 0).rotated(angle)
dash_target = global_position + Vector2(60, 0).rotated(angle)
if dash_target != Vector2.ZERO:
dash_timer += delta
if dash_timer >= 2.0:
if dash_timer >= 1.0:
dash_timer = 0
dashing = true

View File

@ -3,8 +3,8 @@ extends KinematicBody2D
var velocity = Vector2.ZERO
var speed_multiplier: float = 1.0
var slowed = false
var target
var speed = 100
func get_input():
var input_direction = Input.get_vector("left", "right", "up", "down")
velocity = input_direction * speed
@ -25,13 +25,14 @@ func _physics_process(_delta):
speed_multiplier = 1.0
velocity = move_and_slide(velocity * speed_multiplier)
_choose_target()
choose_target()
func _choose_target():
func choose_target():
var least_dist = 4000
var enemy_dist
var enemies = get_tree().get_nodes_in_group("enemy")
enemies.sort_custom(self, "_sort")
for enemy in enemies:
enemies.front().scale.x = 1 #TODO
func _sort(a, b):
return a.position < b.position
enemy_dist = global_position.distance_to(enemy.global_position)
if enemy_dist < least_dist:
least_dist = enemy_dist
target = enemy

View File

@ -73,7 +73,7 @@ shape = SubResource( 3 )
[node name="Enemies" type="Node2D" parent="View"]
[node name="TrashCan" parent="View/Enemies" groups=["enemy"] instance=ExtResource( 13 )]
[node name="TrashCan" parent="View/Enemies" instance=ExtResource( 13 )]
[node name="Bat" parent="View/Enemies" instance=ExtResource( 14 )]
z_index = 1