I am trying to make my enemy aim at the player with a raycast, but the raycast doesn’t move at all. So I added print(playerPos) which prints the same x, y every time it triggers even if I move around. How do I get it to always check the players current position?
if you use get_first_node_in_group() just for addressing one single node in group from any place, try to for instance use one of Engine’s already used singletons like IP to set meta with a player node id like
in player node: func _ready(): IP.set_meta(&'player', self)
in your func aim(): ray_cast_2d.target_position=IP.get_meta(&'player').position
this will make player instance available from any script
Engine’s singletons are initialized before static func _static_init()
IP.get_meta(&‘player’).position could be irrelevant to ray_cast_2d if player and raycast have different parents, if so, use .global_position