Fix Target Selection
parent
fed4a0779a
commit
b121e6a10d
|
@ -1,7 +1,6 @@
|
||||||
extends KinematicBody2D
|
extends EnemyClass
|
||||||
|
|
||||||
onready var player = $"../../Player"
|
onready var player = $"../../Player"
|
||||||
var speed_multiplier = 1
|
|
||||||
var dash_target = Vector2.ZERO
|
var dash_target = Vector2.ZERO
|
||||||
var dash_timer = .0
|
var dash_timer = .0
|
||||||
var dashing = false
|
var dashing = false
|
||||||
|
@ -13,10 +12,10 @@ func _physics_process(delta):
|
||||||
else:
|
else:
|
||||||
if dash_target == Vector2.ZERO:
|
if dash_target == Vector2.ZERO:
|
||||||
var angle = global_position.angle_to_point(player.global_position) + PI
|
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:
|
if dash_target != Vector2.ZERO:
|
||||||
dash_timer += delta
|
dash_timer += delta
|
||||||
if dash_timer >= 2.0:
|
if dash_timer >= 1.0:
|
||||||
dash_timer = 0
|
dash_timer = 0
|
||||||
dashing = true
|
dashing = true
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ extends KinematicBody2D
|
||||||
var velocity = Vector2.ZERO
|
var velocity = Vector2.ZERO
|
||||||
var speed_multiplier: float = 1.0
|
var speed_multiplier: float = 1.0
|
||||||
var slowed = false
|
var slowed = false
|
||||||
|
var target
|
||||||
var speed = 100
|
var speed = 100
|
||||||
|
|
||||||
func get_input():
|
func get_input():
|
||||||
var input_direction = Input.get_vector("left", "right", "up", "down")
|
var input_direction = Input.get_vector("left", "right", "up", "down")
|
||||||
velocity = input_direction * speed
|
velocity = input_direction * speed
|
||||||
|
@ -25,13 +25,14 @@ func _physics_process(_delta):
|
||||||
speed_multiplier = 1.0
|
speed_multiplier = 1.0
|
||||||
|
|
||||||
velocity = move_and_slide(velocity * speed_multiplier)
|
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")
|
var enemies = get_tree().get_nodes_in_group("enemy")
|
||||||
enemies.sort_custom(self, "_sort")
|
|
||||||
for enemy in enemies:
|
for enemy in enemies:
|
||||||
enemies.front().scale.x = 1 #TODO
|
enemy_dist = global_position.distance_to(enemy.global_position)
|
||||||
|
if enemy_dist < least_dist:
|
||||||
func _sort(a, b):
|
least_dist = enemy_dist
|
||||||
return a.position < b.position
|
target = enemy
|
||||||
|
|
|
@ -73,7 +73,7 @@ shape = SubResource( 3 )
|
||||||
|
|
||||||
[node name="Enemies" type="Node2D" parent="View"]
|
[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 )]
|
[node name="Bat" parent="View/Enemies" instance=ExtResource( 14 )]
|
||||||
z_index = 1
|
z_index = 1
|
||||||
|
|
Loading…
Reference in New Issue