overlapping families

Get help using Construct 2

Post » Wed Sep 20, 2017 8:47 pm

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
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Sep 20, 2017 9:33 pm

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.
B
48
S
19
G
87
Posts: 2,314
Reputation: 51,512

Post » Wed Sep 20, 2017 10:01 pm

@plinkie 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 :)
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Sep 20, 2017 10:18 pm

@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
B
47
S
29
G
91
Posts: 343
Reputation: 50,714

Post » Wed Sep 20, 2017 10:46 pm

@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 :) and the on collision wont work as they will keep fighting each other to someone dies so i need it to continue on every 2 seconds which it does :)
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Sep 20, 2017 10:54 pm

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.
B
48
S
19
G
87
Posts: 2,314
Reputation: 51,512

Post » Wed Sep 20, 2017 11:12 pm

@plinkie thats the problem i don't want them all to take damage from each person overlapping :) despite how many people are overlapping i just want each object to damage 1 object and not all of them :)

sorry im terrible at explaining things :(
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Sep 20, 2017 11:34 pm

I would do something like this:

Code: Select all
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


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.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
125
Posts: 1,735
Reputation: 66,791

Post » Thu Sep 21, 2017 12:25 am

@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 :) now i just go to change the code a bit so it will work properly with animations :) thanks a ton
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Thu Sep 21, 2017 6:39 am

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:

Code: Select all
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           
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
125
Posts: 1,735
Reputation: 66,791

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 11 guests