Boomerang throw

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fefinfon

I have a player node with its own script and other node (wich is a boomerang) with its own script too. So, when i press the mouse click button, the boomerang script will execute (throwing the boomerang until it comes back to its start position) and at the same time, the player script will reproduce “throw” animation. The boomerang scrip causes the boomerang to “fly” and when certain time passed “return” to its parent and once it returned you can throw it again. But when I put it as a child of player, it deppends on the players action. I don’t know if this is clear, but if I press click, boomerang will come out, but then if I click again another boomerang will come out before the first one returned.
I thought on add a timer to it, but the return will vary on the players position after throwing the boomerang, so I don’t think a timer will work well on this case.

Thanks in advance.

You made the boomerang node to not be a child of the player node? You very much should already do it.

You also will need to add a timer, for a different purpose though.

You could make a global variable in player node, a simple boolean like is_boomerang_ready, set by default to true.

Anytime you press the Boomerang release button™ it will first of all check if is_boomerang_ready is true, boomerang gets released - you set is_boomerang_ready to false.

Somewhere in _physics_process there has to be a function to check if the boomerang has returned, let’s call it has_boomerang_returned(). A simple way to do it is to check if it’s position is equal to player node’s position, maybe with some room for error too?

Obviously there has to be a certain amount of time between you throwing, and checking if it’s back already. You will have to start a timer at the throw, which will make has_boomerang_returned() executable.

Feel free to ask for any clarifications, some people might even want to make that script for you.

denexter3 | 2021-06-02 17:51

Hi! thanks for your answer! I think I’ve already done that, but I’m not sure if It’s ok…
Maybe some images will help to better show what I’ve done

Boomerang script

Player script


fefinfon | 2021-06-03 00:11

First of all, don’t post images of your code. Always copy & paste it.

Where is boomeran_throw() used? I can’t see it in either attack_state() nor shoot_state().
So, is_shooting is set to true whenever you press the Boomerang Release™ button, the boomeran_throw() gets called, somehow.
Said boomerang gets instantiated, and flies through the sky, and deletes itself after it gets to its target.

But that’s about it, is_shooting is controlled by player Input, there is no check for if boomerang is ready, or even if it already got back to you.

denexter3 | 2021-06-03 07:54

Hi! sorry about the images!

Boomerang_throw() is a method call on animation player to make the boomerang launch with the shoot animation.
And it adds a child (new_node)
new_node = BOOMERANG.instance()
const BOOMERANG = preload(“res://escenas/boom.tscn”)

boom scene is the boomerang

“But that’s about it, is_shooting is controlled by player Input, there is no check for if boomerang is ready, or even if it already got back to you.”

That’s what I wanted to know. Is there a way to do it? Or is it a bit impossible with this code?

If I play the boomerang scene by its own, another boomerang won’t come out until the first one is back. The problem is when I make the boomerang launch depending on the shoot state

sorry for my ignorance, I’m an artist trying to script

fefinfon | 2021-06-03 18:52