I followed a tutorial on how to make enemies follow players on youtube. It was made for godot 3 and many little things had to be changed. Now all error messages except for one have disappeared.
I would guess your player isn’t in a group named “Player”
To access a node you must use the dollar sign
@onready var player = $/root/game/player
This may still not result in finding the player, It’s a bad idea to search for parent nodes on ready, the group method isn’t bad but you need to add your player to a group named “Player” then you can use this shorter function
func _ready() -> void:
player = get_tree().get_first_node_in_group("Player")
it means you are trying to get a ‘position’ from a variable that holds nothing.
In this case “global_position” is what you are trying to access, and “target_to_chase” doesn’t hold anything, so it gives that error.
target_to_chase.global_position
Did you assign your enemy “Node2D” a character in the inspector? If you are using @export, which is a good idea, then you will have a new property to assign, named “Target To Chase”. Click the Node2D again and check your Inspector.
I don’t know why the group method didn’t work unless the group assigned does not match the group you have in the script.
Yes, I assigned it to the player within the scene where they both are. I was not able to assign it in the scene where only the enemy is, as it could only access nodes that were present in the scene. So within the scene I’m trying to load, the enemy is set to chase the player.
Both group and player and all that is “player” with same caps.
I think maybe it would be better if I return to this problem in a while when I know more.