This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Well on progress in the game there will bullets get generated and like in space invader, there will get enemies generated.

on my main Node i want to check if bullet and enemy are colliding or not.
i dont want to write that code into the bullet or the enemy, because they re not there all the time and in futur i want to reuse the scene maybe.

so how can i chack from my main-node, if node-bullet and node-enemy are colliding?

in Engine by (67 points)

3 Answers

0 votes

To communicate your collisions back to your main node without putting code on your bullets or enemies.... for that, you will need signals.

Your bullets will need collision nodes, as will your enemies. You could use your bullet object with a child of Area2d, and the Area2d has a child of collision. Don't forget to set your collision shape. Do the same setup for your enemies.

Now use your signals, like "body_entered", and point them back to functions in your main node for evaluating those collisions.

Here's a great video on explaining signals which should be a big help: Introduction to Signals in Godot (tutorial)

by (337 points)
0 votes

You'll need to detect the collisions on the sprites (as per usual) with the node event 'onareaentered' and have that use a function on the sprite to send a signal to the main script which will handle the logic.

by (36 points)
0 votes

hi. thank you for your answers. i know how to put a signal. but you cant put a signal to an parent who doesnt exists.

my bullets and the enemys arent in the scene till they will get generate

by (67 points)

I think you should have a main scene which will have a script attached. This script can receive signals generated by child objects (bullets/enemies). If you don't have a main scene with a script then I think you might be making things difficult for yourself. Look at the tutorial for some inspiration:

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.