Baton only attacks once and thats all

Godot version is 4.1

 extends Node

@export var weapon_ability: PackedScene

func _ready():
const MAX_RANGE = 150
func on_timer_timeout():
	print("do something")
	var player = get_tree().get_first_node_in_group("player") as Node2D
	if player == null:
	var hoodies = get_tree().get_nodes_in_group("enemy")
	hoodies = hoodies.filter(func(hoodies: Node2D):
		return hoodies.global_position.distance_squared_to(player.global_position) < pow(MAX_RANGE, 2)
		return false

	if hoodies.size() == 0:
	hoodies.sort_custom(func(a: Node2D, b: Node2D):
		var a_distance = a.global_position.distance_squared_to(player.global_position) 
		var b_distance = b.global_position.distance_squared_to(player.global_position) 
		return a_distance < b_distance 
	var baton_instance = weapon_ability.instantiate() as Node2D
	baton_instance.global_position = hoodies[0].global_position

How to make the baton attack the enemy multiple times? It only spawns on the enemy once and doesn’t come back despite the enemy being closer to the player. This is for a school project

Check the “One Shot” property of your timer. If it’s on, the timer will only timeout once.

1 Like

Holy Moly it worked thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.