Because you are not using correct node paths. I'm assuming this script is on fighter
.
Writing $fighter
means get_node("fighter")
, which means "Get a child of this node named 'fighter'". fighter
doesn't have a child named "fighter", so you get a "null instance".
In addition, you're also trying to use $fighter2
, which also isn't a child of the scripted node. The path from fighter
to fighter2
would be "../../fighter2/fighter2"
. I don't know why each of your Sprites has a Node2D parent, but that's another issue.
If you're having trouble understanding node paths, you might find this helpful:
http://kidscancode.org/godot_recipes/basics/getting_nodes/