Calculate the damage inflicted

Here’s a setup that fires a bullet with either the default red animation or a purple animation. It uses a damage variable to calculate the damage. If the bullets were in a group, then the objects could have a preset object variable. Since it checks each bullet separately it doesn’t need to multiply the select count because it will always be only 1.

1 Like

Thanks Keith for taking the time.
There are different types of weapons and each one inflicts different damage.
I created a small game project and followed your events but the text “NaN” is created.
I’m definitely doing something wrong… I’ve attached the file, could you take a look at it when you have time? I’m going crazy hahah

When I can I’ll look at your project. It sounds like it’s trying to convert text to a number or add text that’s not a number. The same original happened to me because I didn’t set the default text value of my text object to 0. It was set to text.

Edit: That was the issue the initial text needs to be 0
image

Also, make sure all of the events use the group name for the bullets.

This is missing the period in Bullet.2
image

Setting the default value for the damage object variable for the bullets and changing the first collision to use the bullets group seems to work. Plus I added a delete Bullets.

1 Like

sorry for my absence… I did as you suggested and now it seems to be working! thank you so much

1 Like


in the event that the bullets pass through the enemies and are not cancelled, the value is calculated several times.
How would you handle this?

There are posts about this.

I would use a structure. Add the ID variable to each enemy as a string, give them a value based on a counter variable. Give the bullet object a structure named IDs

Events

project: (click green [code] then [download zip]

This might need more testing. But it’s a start

I’d prefer to use the linking version. That wouldn’t require IDs. I tried to make it but it didn’t work. If I get it to work. I’ll share it.

1 Like

I was rewriting the events by removing the health behavior and added a damage value to the projectiles and this is what happens:
Registrazione bullets


the last enemies take no damage.
I am attaching the file again if you have the opportunity to take a look I would be grateful.

I’ll take a look at it to see what is happening but I was able to figure what was wrong with my linking. I needed a pick all.

Edit: I looked at your project and the enemies didn’t have unique IDs. That’s one of the reasons why I try not to use IDs.

This version doesn’t need any variables or IDs. As always, it needs testing.

Updated with a screenshot of all of the events.

project
https://github.com/doug13579/gdevelop-multiple-bullet-one-time-hit-2

1 Like

The message was deleted just as I was replying. I don’t know if that means you realized that the text object was being added but the text wasn’t being changed.

There’s a 2nd part to my example that I didn’t screenshot but should be in the project file. Sorry about that. I’ll update the previous post.

In your version, you would need to link the text object to the enemy after it’s created. In my test I added the text objects and linked them in the beginning. I was testing the linking part not your entire concept.

Yes, I deleted it because I realized that the text was not calculated anywhere
In the previous example where should the “pick all” be added?
I was also trying the second one but there are several problems including the text is calculated infinitely when the enemy and the projectile are linked and the text is deleted simultaneously on all the enemies to which it is linked

I’m trying it using your concept and it’s not working for me. Let me look into it.

1 Like

the first concept works very well except that the IDs are not calculated correctly.
in my project I am not using any type of behavior

OK, this doesn’t delete the text object but it’s only creating 1 text object and it’s only adding the damage once per collision.

try me:
https://gd.games/keith_13579/single-hit-bullet

sorry but I’m still having problems…
this is what happens:
bug
the second enemy suffers the hit twice while the third is not counted

I don’t know why this is for each player. It should be for each enemy
image

I think. My bullets weren’t as close together.

My current events

all updated, fingers crossed

To include a tween, I think this works.

unfortunately no it doesn’t work
examplegif

Well. What’s happening is my concept isn’t exactly like yours. I wasn’t using groups. I just rewrote it with groups and I’m going to see what the issue is. It seems to be when multiple objects collide. it might need a scene variable instead of the pick all. The pick all is picking too many.

Ok, so I added a scene variable Boolean variable called IsLinked. The inverted link condition just wasn’t working as expected. And trying to repick just 1 bullet and enemy wasn’t working. It’s easier to use the current pick list.

Try me: (I added a health display to check that everyone was getting the correct damage)
(I added 2 bullets using left or and right mouse button)
https://gd.games/instant-builds/db21e0fa-d8fc-4945-94c9-a82ba9360162

All of the current events

I’m going to update my GitHub.

Version 3.
https://github.com/doug13579/gdevelop-multiple-bullet-one-time-hit-3

1 Like

great! works!! thanks for everything @Keith_1357

1 Like

I was writing the events in my project but I realized that if the projectile is eliminated in collision with the enemy the hit is not calculated
prob