|Topic was automatically imported from the old Question2Answer platform.
New Godot user here, and so far loving it!
Just one question though…I have a 2d fighting game, street fighter type. I managed to solve the problem of flipping the character (independent scene) sprite so he always faces the oponent when jumping over each other. Both characters exist in the main scene as children of a generic Node (the white ones). The flipping is done in a script attached to both characters (the exact same script) where one character gets the other with a referenced variable at
func _ready() using the
get_parent().get_child() method, and then compares the x position of the oponent with his own x position (the comparation is done in a function under
func _process(delta) ).
Here’s the thing…Is this legit? are there more orthodox methods? As I understand so far, the mantra is “signal up, call down”, so, maybe when dealing with “sibling” nodes, the interaction between them should be done in a script in the parent node? Or maybe using custom signals? However, I don’t think signals are the right tool when you need to compare two objects in relation to one another all the time, or maybe I’m wrong?
Anyway, any input shedding some light is more than welcome.
Thanks a lot!!
It makes more sense for the parent node to have the script. It can reference both children easily, plus if you have a lot of “get_parent.get_child()” in your script it could get rather confusing.
Millard | 2020-08-06 15:40
Yeah, I thought the same, plus the the script for the player was getting really bloated.
yomato84 | 2020-08-07 13:10