|
|
|
|
Reply From: |
p7f |
there are many ways to do so, depending on your implementation. For example, in my game, i create fireballs in the player’s script. So i instance a firebal, and connect it right away, and then i add it to the level. Something like this in the player’s script, when you shoot the fireball:
# FireBall was preloaded before
fireball = FireBall.instance()
# on_fireball_finished is a method defined in players script
firefall.connect("finished", self, "on_fireball_finished")
# add fireball where it belongs
get_tree().get_root().add_child(fireball)
# change fireball's position if needed after this
However, you could also have a Global script attached as an autoload, and have a reference to the player there. Anytime you instance a fireball, you could connect to the player on the fireball’s ready:
# Fireball's ready
func _ready():
connect("finished", Global.player, "on_fireball_finished")
or something like that. If you provide a test project, i can help you further.
The first one works for me, thank you. As a new comer to Godot, some times is quite confusing with the relationship of Nodes, Scripts, and Scenes, guess it will take some time and practise to get a better understanding. Thank you very much for your help.
One more question, in my game, I want to have a charge state, when press and hold down a key, the player stays in the state. When the key is release (or not longer be hold), the play goes to a normal state. In order to trigger the state change, is Input.is_action_pressed a good way to go with? I tried this, but the behaviour is less than reliable, I am not sure if use other options like input(event) will be better. It would great to get some advise, thank you.
Idleman | 2020-07-09 06:16
Hi! I saw your other question today. I usually use Input.is_action_pressed
in process if i only have to check that key in certain states. I use _input(event)
for keys that should trigger an effect regardless the current state. I always found that reliable. Ill look at your other post today and see if i can help.