im making a tower defense, and im trying to figure out bullet damage, right now its sending a signal on impact, but this doesnt work, unless im doing it wrong, is there another way of handling bullet damage thats easier and makes more sense?

This discussion was caught in the moderation queue since you have not confirmed your account yet.
Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.
If you need any help, please let us know! You can find ways to contact forum staff on the Contact page. Thanks! :smile:

Sending a signal on collision is one way to do it. Probably a good choice too. It should work, maybe there is a mistake in your code.

@cybereality said: Sending a signal on collision is one way to do it. Probably a good choice too. It should work, maybe there is a mistake in your code.

That's what I thought, so I have the bullet emitting a signal, it then goes to the bullet manager, and then the bullet manager is supposed to send it to the enemy, does that seem correct?

One way would be to check collision on the bullet. If it collides, check that the body is of enemy type. If so, send a signal to the enemy and process the collision. You can also just call a function on the enemy without signals. Though this is less proper than signals, it would be easier and less complicated.

@cybereality said: One way would be to check collision on the bullet. If it collides, check that the body is of enemy type. If so, send a signal to the enemy and process the collision. You can also just call a function on the enemy without signals. Though this is less proper than signals, it would be easier and less complicated.

How would I be able to do both with different damage input? Would there need to be anything special so I only affect that enemy?

The bullet can be a scene with a script, then you can set the bullet damage when you instance it. Then when it collides you can check the group and then process the damage. See this thread for some code when using is_in_group. https://godotforums.org/discussion/21342/how-to-i-check-if-the-collising-object-is-in-a-particular-group-in-kinematic-body-2d

Then you can apply the damage set when you instanced the bullet. If you have a lot of bullets, like a bullet hell type of game, then this may be slow and you'd want a manager type class to move the bullets and such, but you can probably have a few dozen at least using code on the bullet and that should be fine.

how would i link the enemies up to the bullet if they dont exist?

You can add enemies to a group (see on the right side of the inspector with the tab). Then you can use the code on the link I posted to check if the collision body is an "enemy" and then do something to them. You can connect signals in code, but you can also just call a function on the enemy (have to cast it to an enemy object first).

I just called the script instead of using signals, it's easier and I think more efficient, but now I'm having a different problem lol, I wish there were better tutorials

2 years later