overlapping families

0 favourites
  • 13 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • hi there i got a bit of a curious question. ive got 2 families that move towards each other then when they overlap they stop, then start doing damage to each other via every 2 seconds subtract health from family by object.damage.

    this works well to a degree, what i want is to have 1 object pick another object from another family and do damage to that instead of all the objects. ive tried pick random and pick nearest but neither has worked any suggestions?

    im debating trying pick by UID but that will require quite a bit of recoding

    thanks for any help

  • [quote:1efoo8jz]what i want is to have 1 object pick another object from another family and do damage to that instead of all the objects.

    Not 100% sure on this, can you be more specific or give an example? Based on what you already have with two different overlapping families taking damage and working as you expect, I don't quite get it.

  • okay ill try reword it, i have demons attacking humans and humans attacking demons and alot of the time they stack ontop of each other so the problem i have is when the demons attack all the humans usually get wiped out in 1 hit and i would rather each demon focus one human each and the same vice versa. the humans have about 80 health and demons 12 attack which means it should take at least 7 hits to kill but instead all the demons focus all the humans at the same time so if there are 7 or more demons attacking all humans overlapping those demons get killed instantly. hopefully i worded it abit better this time

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • darkrealos

    There are two things it may help to fix your problem:

    1- The overlap it may not be suitable for this task because when (object1) is overlapping (object2) it will subtract from health that quick that you wouldn't even notice as the overlap is true every thick that's why the health goes that quick, you can replace with on collision maybe

    2-If you need to apply some actions to objects of the same instance individually remember to use the (For Each) to that object so it will apply to all of the instances individually

    You can find the "For Each" in System>>>For Each>>> Then choose the object

  • tarek2 ahh sorry i should of mention it is on for each family. so that it selects each unit and the code does work in a sense because ive done it where it overlaps with 1 or 2 units and it takes the correct amount of hits to kill them the problem is that they hit all the objects at the same time instead of hitting them 1 at a time

  • This shouldn't really be broken unless you've not been consistent with the picking i.e. If you said something like demon overlapping human object but then subtracting health from a family then it could break. Otherwise each demon should just take damage from each human's health when it is overlapping.

  • thats the problem i don't want them all to take damage from each person overlapping

    sorry im terrible at explaining things

  • I would do something like this:

    System -> Every 2 second:
    
    For each Humans
      If Humans is overlapping Demons
        Pick random Demons 
          Human -> deal damage to that Demon
    
    For each Demons
      If Demons is overlapping Humans
        Pick random Humans
          Demon -> deal damage to that Human
    [/code:1wcd90bu] 
    
    Instead of Humans picking different random enemy every 2 second, you can pick a random (or weakest, or strongest) Demon once, save it to a Human's instance variable and then only fight this Demon. While they are still overlapping of course.
  • dop2000 thanks for the reply the only thing i don't get is how to save that object to a variable

    update i tried what you said and it worked a charm thanks a ton

  • [quote:26wjzmqs]the only thing i don't get is how to save that object to a variable

    Create an instance variable "TargetUID" on Humans family.

    Then you'll need to change your events to something similar to this:

    System -> Every 2 second:
    
    For each Humans
      If Humans overlapping Demons
      and 
      Demons.UID=Humans.TargetUID  
          Human -> deal damage to that Demon  (previously selected as a target)
      Else  
         // means either TargetUID is not set or that target Demon is no longer overlapping with Human or dead etc.
        System -> Pick all Demons
        If Humans overlapping Demons
           Pick random Demon
               Human.TargetUID=Demons.UID
               Human -> deal damage to that Demon           
    [/code:26wjzmqs]
  • tarek2 ahh sorry i should of mention it is on for each family. so that it selects each unit and the code does work in a sense because ive done it where it overlaps with 1 or 2 units and it takes the correct amount of hits to kill them the problem is that they hit all the objects at the same time instead of hitting them 1 at a time

    I see what you mean now, and also I see that dop2000 gave you a really good solution

    one thing I I will add to the dop2000 example I hope you don't mind is that you don't need the "For each" in this case other ways it will happen the same thing that you trying to avoid

    Example:

    Health 80

    Every Hit = Takes 5 from health

    So if three Humans overlap one Demon the Human will take damage 5 x3 =15 each hit you will fix this by removing the "for each" unless you wanna that to happen

    capx >> all credits goes to dop2000

    https://www.dropbox.com/s/7t882fw34ekelt8/Overlapping%20Families%20Pick%20One.capx?dl=0

    Drag the Humans and vice-versa and place them between the enemies to see them taking damage

  • darkrealos

    You know what forget about my capx will not work either sorry for that, I just noticed that if you place three different groups of one Demon Vs one Human then this will happen:

    Two of that group of three will be waiting until that random pick>> it picks one from that group, meaning that Two of the groups it can be (Human overlapping Demon) and both of them not getting hit for several seconds because the pick random didn't pick them yet so they can be there fighting each other but not getting Damage.

    so basically this is a bigger problem than it looks jeje so now the question is how exactly you wanna to happen and how your game will be working, example:

    will it be different groups of Demons vs Humans fighting far from each other example first group here and another group at a farther distance if so how you wanna resolve the hittings Damages pick every 2 secs Random from each group independently or just pick one (demon and one human) from all the objects and apply the damage, you need to be more concrete here because there are many scenarios that can happen that can break the logic that you wanted in the first place

  • dop2000 thanks for the reply i did think about using the UID to target

    ill give it a try at some point thanks

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