fix enemy aligning, add sticks respawn
This commit is contained in:
+19
-3
@@ -116,11 +116,24 @@ func _chase(delta: float) -> void:
|
||||
target.take_damage(damage_to_player)
|
||||
if enemy_kick_timer <= 0.0:
|
||||
_try_enemy_kick()
|
||||
var sep := Vector3.ZERO
|
||||
for e in get_tree().get_nodes_in_group("enemies"):
|
||||
if e == self:
|
||||
continue
|
||||
var en := e as Node3D
|
||||
if en == null:
|
||||
continue
|
||||
var away := global_position - en.global_position
|
||||
away.y = 0.0
|
||||
var away_dist := away.length()
|
||||
if away_dist < 2.2 and away_dist > 0.01:
|
||||
sep += away.normalized() * (2.2 - away_dist)
|
||||
if dist > 0.05:
|
||||
var dir := diff.normalized()
|
||||
velocity.x = dir.x * move_speed
|
||||
velocity.z = dir.z * move_speed
|
||||
rotation.y = lerp_angle(rotation.y, atan2(dir.x, dir.z), 8.0 * delta)
|
||||
var move_dir := (dir + sep * 0.6).normalized()
|
||||
velocity.x = move_dir.x * move_speed
|
||||
velocity.z = move_dir.z * move_speed
|
||||
rotation.y = lerp_angle(rotation.y, atan2(move_dir.x, move_dir.z), 8.0 * delta)
|
||||
velocity.y = 0.0
|
||||
move_and_slide()
|
||||
|
||||
@@ -140,6 +153,9 @@ func _try_enemy_kick() -> void:
|
||||
var k := node as Node3D
|
||||
if k == null or not is_instance_valid(k):
|
||||
continue
|
||||
var kfv = k.get("fly_vel")
|
||||
if kfv != null and Vector2((kfv as Vector3).x, (kfv as Vector3).z).length() > 15.0:
|
||||
continue
|
||||
var d := (k.global_position - global_position)
|
||||
d.y = 0.0
|
||||
if d.length() < nearest_dist:
|
||||
|
||||
+24
-4
@@ -108,11 +108,31 @@ func _spawn_rocks() -> void:
|
||||
for i in range(limit):
|
||||
_spawn_single_rock()
|
||||
|
||||
var sticks_on_field: int = 0
|
||||
var sticks_pending: int = 0
|
||||
const STICK_LIMIT := 2
|
||||
|
||||
func _spawn_sticks() -> void:
|
||||
for i in range(2):
|
||||
var stick := STICK_SCENE.instantiate()
|
||||
stick.position = _safe_item_position()
|
||||
add_child(stick)
|
||||
for i in range(STICK_LIMIT):
|
||||
_spawn_single_stick()
|
||||
|
||||
func _spawn_single_stick() -> void:
|
||||
var stick := STICK_SCENE.instantiate()
|
||||
stick.position = _safe_item_position()
|
||||
add_child(stick)
|
||||
stick.connect("destroyed", _on_stick_destroyed)
|
||||
sticks_on_field += 1
|
||||
|
||||
func _on_stick_destroyed() -> void:
|
||||
sticks_on_field = maxi(0, sticks_on_field - 1)
|
||||
if not game_active:
|
||||
return
|
||||
if sticks_on_field + sticks_pending < STICK_LIMIT:
|
||||
sticks_pending += 1
|
||||
await get_tree().create_timer(20.0).timeout
|
||||
sticks_pending -= 1
|
||||
if game_active:
|
||||
_spawn_single_stick()
|
||||
|
||||
func _spawn_single_rock() -> void:
|
||||
var rock := ROCK_SCENE.instantiate()
|
||||
|
||||
Reference in New Issue
Block a user