Invalid get index 'global' (on base: 'KinematicBody2D ('player.gd'))

Viewed 814

I'm trying to make the enemy bullet follow the player, but the error: invalid get index 'global' (on base: 'Kinematicbody2D ('player.gd')) always pops up. When I looked this up, I found some problems similar to mine. The solution says to check the reference, but when I checked the reference, it looked right.

func atirar():
    var dog = tirim.instance()
    get_tree().get_root().add_child(dog)
    dog.global_position = global_position
    dog.add_to_group("delete_on_restart")
    dog.dir = (get_tree().get_nodes_in_group("player")[0].global.position - global_position).normalized()

func _ready():
    add_to_group("player")
1 Answers

dog.dir = (get_tree().get_nodes_in_group("player")[0].global.position - global_position).normalized()

it's a typo, it should be global_position

 dog.dir = (get_tree().get_nodes_in_group("player")[0].global_position - global_position).normalized()
Related