How do I prevent a bullet from hitting multiple instances that are on top of each other?

0 favourites
  • 13 posts
From the Asset Store
Antisuspend Plugin for Construct 3 prevents the runtime from getting suspended.
  • I currently am making a rts game. I have an issue where if multiple units are on top of each other (in the same position) one bullet damages all of them. I tried adding some code to pick just one instance, but that doesn't work.

    Code relating to bullet and object collisions

  • Add a system pick Nth instance condition to just get 1 from the currently picked instances.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I added that, but it still damages all objects stacked, but not ones elsewhere. Am I doing something wrong?

  • Image (it didn't show up earlier)

  • I'm not sure what's going on here. It looks fine to me, unless there is a quirk of families I'm not aware of.

    Are there any other events that can modify health?

  • Fixed it; I believe it had a quirk with families.

    I used the de-bug layout and it would select the 0th instance, destroy the bullet, apply the damage, but then select the [new] 0th instance, destroy the bullet again (fail?), apply the damage to the now 0th instance, and so on. The UID ensures that the event isn't trying to use the same bullet to damage multiple objects by checking the UID of the bullet isn't destroyed because once the bullet damages one instance it is suppose to be destroyed.

    Image:

    Btw: it would be nice to be able to edit posts here, no other forum I have used lacks this ability.

  • it is not a quirk of families, the "On Collision" is a trigger and gets triggered for each instance it collides with.

    you do not need the pick nth instance (the second condition) because the code will get triggered for each instance regardless when the instances are overlapping. You can verify that by checking the AFaction.PickedCount.

    Your solution of setting the BBullet's instance variable is a good way to handle it. I would probably call the instance variable something like "Kills" and set it to a number like 1, then on each collision subtract 1 and if it gets to 0, destroy the bullet. So, that last condition would then say "BBullet.Kills > 0" to allow the collision to damage the AFaction.

    This would allow stronger bullets that could potentially kill multiple enemies.

    EDIT: oh yeah, I can edit comments, so I guess you may have to wait until you have posted enough comments before you can edit?

  • Oh interesting. I was using On clicked object and it was working fine.

  • for the stuff I normally do, I use "Is overlapping object". Unlike a collision trigger, "is overlapping" will pick multiple objects at the same time (if they are overlapping). Then I use Pick top instance to get only one.

    "On clicked object" works that way too. (picking multiple instances)

  • Btw: it would be nice to be able to edit posts here, no other forum I have used lacks this ability.

    In the top of your post, there should be an "Edit" button right there for this very purpose. Is it not available to you ?

    I do not recall editing one's post being limited/restricted.

    Tom Could you confirm ?

  • I see. Thanks for the help with the issue and for the advice about being able to hit multiple enemies.

    Also, I have no edit button available to me.

    Image:

  • Do you see it now ?

    There is a limitation; you need to post a few posts before accessing this feature.

    This was implemented to prevent spam accounts editing their posts.

  • Not yet, I guess I'll wait and post some more.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)