Make two objects in the same group interact with each other

Greetings,

In my game, I have object groups to separate logic.
One group called Entities, to classify any living thing, like the player, enemies, etc
And another called HarmfulThings, used to classify things that can hurt the entities

Here’s the issue, I tried adding a test enemy that does contact damage to the player. Since it’s an enemy, it qualifies as an entity. But since it deals contact damage, it also qualifies as a harmful thing. Thus, I put it in both groups

However, the player’s attack is also in the HarmfulThings group, so both the enemy and my attack are in the same group, and they cause issues

Here’s what happens when the enemy is NOT in the HarmfulThings group. Everything working as intended:
issue

But if the enemy IS in the HarmfulThings group, he’s impervious to all damage:
issue

Is there a way to make objects in the same group interact with each other? Or am I just gonna have to resort to a workaround?

Can you post a pic of the events or add a bit more context?

Either GD doesn’t know which object is which because they’re in a group or when 1 object is picked in the group, you can’t pick any others. For example inside a for each object using the group name.

It’s easier when objects are clearly defined in seperate groups like enemies and projectiles but I understand there are times when the same thing happens to a player and enemy and you want to streamline your events using groups.

Adding object variables might help. Creating functions or behaviors might also simplify things.

Unfortunately, you can’t filter picklists using the object name. So, sometimes using an object variables condition can help. Maybe even a prefab object or two.

You can also sometimes use the count number of picked objects condition to tell if you have 2 of the same object or 1 of each.

If apples and oranges were in a group then the following wouldn’t work. Because only an apple or orange would be picked at a time.

For each object in FruitGroup
… Apple is in collision with orange

The best you could do is either add a test object or save one of the object’s location and compare it to the other. Either method isn’t optimal or really recommend. Although, sometimes it works with a limited number of instances.

1 Like

Thanks for the insight, I’ll try to come up with a workaround for the problem, maybe making a separate hurtbox and attaching it to the enemies?

Right, here’s the code that calculates how damage is inflicted:

Which objects are in which groups? A pick all in between the conditions might help. If objects in the 2nd group are also in the first group then they could be filtered out by the 1st condition. You might need to repick the 2nd group name before checking the 2nd variable.

Ahh, sorry for excluding that info, here’s the Entities group:


And here’s the HarmfulThings group:

You can see the TestSpikeEnemy is in both groups here

I attempted to use Pick All between the conditions, but it resulted in everything in the group taking rapid damage

What specifically do you mean by filtering out objects in groups? Is there something that allows me to narrow it down?

Sorry. Conditions act like filters. They only pick the matching objects. It then passes that list to the next condition and subevents which can then further “filter” the pick list.

TestSpike might need its own condition or maybe just use pick all with test spike.

Sure, TestSpike having it’s own condition may be a short term solution, but in the long run, once the game grows and I have more enemies that can do contact damage, I’m gonna have to add a condition for each one, which wouldn’t be ideal, which is why I used the groups

I’m gonna try adding a hurtbox object, which will be the damaging hitbox. This will be in the HarmfulThings group, while the enemy can stay in Entities

1 Like

Agreed. You want your events to be dynamic and function the same no matter how many objects are in either group.

If friendly can be true or false then is it necessary to check its value? You might be able to just check if hurtEnemy is true.

If multiple objects can collide then you might need to add a for each object for things like the UID but it becomes complicated with an object in both groups.

I’m going to continue with my apple and orange.

If an apple and orange were in collision then the pick list for apple and orange would contain 1 object each.

If the object’s were in a group then the group pick list would contain an apple and an orange. If you were to try to read an object variable using the group name then it would only read 1 object. It might read the orange instead of the apple.

I don’t know if that’s your issue. You might need a for each object to check the right values and to set the values.

In testing I had issues because the collision event was triggered when different objects collided or objects of the same type because I was using a group list with both objects.

If you had projectiles in collision with objects. It would be clear which ones are the projectiles and which are the target objects.

If they were in the same group then you wouldn’t know which was which and you might apply damage to the projectile instead of the target object. The solution might be to apply damage to both objects or use a condition to ignore projectiles by maybe using an object variable named IsProjectile. In your case maye the solution is to use a for each object and update the variable of both objects if they have different UIDs.

IDK anything about how you’re using the UIDs. So, that might not be an issue.

1 Like