+2 votes

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.

Godot version Godot v. 3.3
in Engine by (19 points)
edited by

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.

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
https://drive.google.com/file/d/15opyvP46SeimFL8Kzzh-WD0WpA7YJIlt/view?usp=sharing

Player script
https://drive.google.com/file/d/1pPo06vgrqT3QOIkl1_K298bKwwJfn9i2/view?usp=sharing

scenes
https://drive.google.com/file/d/1JePuX9dxI3PKnJSeybFdJFFozhppoteI/view?usp=sharing

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.

Hi! sorry about the images!

Boomerangthrow() 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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.