[SOLVED] Is it possible to create collision object groups and masks at run-time?

Hi!

I’m currently developing some sort of “build and fight” game, and the “battle” gameplay in some aspects looks like a RTS game (pvp, units vs units etc.).

For now, I’m encountering 1 major issue: the collisions (preventing me from having massive battles for now).

1/ I did not implement a crowd management system yet, so my units tend to overlap each other pretty often
2/ both the units and the projectiles have a collision box (“unit” and “projectile” group/mask, detecting each other)
==> each projectile can collide with several unit at the same time, even though this is not its target
3/ so… the potential number of simultaneous collisions can be insane
image
(it may not be super obvious on this screenshot, but several units (and thus their collision boxes) are currently overlapping with each other)
image
(super extreme situation of course, with 100 overlapping units and 100 projectiles colliding at the same time… Won’t happen but you get the idea)

And once the limit is reached, the collisions are ignored, the projectiles are not deleted, and… this is a mess.

I could increase the max nb of collisions in the project settings, but that would not really fix the issue.

SO the ideal solution would be to have the possibility to dynamically create collision masks and groups (so a projectile would collide with its “official target” only)

I found this:

physics.set_group()

But…
“The group name should exist i.e. have been used in a collision object in the editor.”

Does that mean that I can’t create group names at runtime? (which isn’t very convenient in a “massive battle” situation, where I want each projectile to hit a specific unit only - the mask/group would be unique strings that can’t be created in the editor)


So I have 2 questions:

1/ It is possible to dynamically create collision masks/groups at runtime? (would be the ideal solution :nerd_face:)

Or it’s not:

2/ What would you recommend in my situation to manage the “collisions” between units and projectiles? (in a “massive pvp battles” context)

2b/Should I use something else than Defold collisions? Maybe based on the distance?..


Thanks!!

You can use the physics.set_mask_group() et.al to manipulate your groups/masks.

You can also enable/disable collision objects.

I think it’s probably a good idea for you to group your objects together (e.g. in a “squad”) once a collision between units has been detected, so that you can make then choose some new target position nearby (so they don’t overlap too much)
E.g. there is DefArmy that does something like this.

3 Likes

Not sure to understand:
“The group name should exist i.e. have been used in a collision object in the editor.”

Looks like I can assign existing groups-masks, but I can’t create new masks and groups at run-time.

Or maybe the description is not up-to-date?

Interesting, thanks!! :slight_smile: I’ll take a look at it and see if it fits my gameplay needs.

Correct. Masks are usually a very limited resource anyways, max is currently 16 (a limit within the physics engine(s), not Defold), due to the fact that they are stored as bit masks.

1 Like

Ok I see!

In this case, maybe Defold’s collision system is probably not recommended for what I want to do?

Since I don’t focus on controlling ONE character, I don’t need pixel-perfect collisions, so maybe a simple distance check could do the job :thinking:

DefArmy seems reaaaally cool but designed for large-scale RTS battles like Total War, with big/clean battle areas, etc. I’ll probably use it someday (because it looks amazing) but I don’t think I’ll work for my current prototype. And I don’t want my gameplay to be defined by such constraints.

In my case, these are fast-paced battles taking place in limited/closed arenas with obstacles etc. a mix between clash royale and warcraft. I’d like to have something more “organic” that Total War, more individual / less group-based.

Anyway, I think I’ll go for the alternative collision system mentioned above, except if you think this won’t work??

I am also struggling with this problem. For example, I want to use the same collision object for two different purposes, so I assign it to two different groups (One group uses the original collision object, the other with the same but 1.1x magnification). Each collision object is inside a game object along with a script. The script has a property to dynamically set the group for the collision object. If I do not enter these two group names statically for one of the collision objects in the editor, I get an error message at runtime: Collision group not registered: …

I still don’t know what a nice and clean solution to this problem might be. Wouldn’t it be luckier to statically list all possible collision object groups in the physical section of the game project settings? When compiling, the editor would check that the statically configured groups and masks match this, and the engine would know the possible group names and there would be no problem with dynamic setup.

(just implemented a simple “handmade” collision system and it works fine :nerd_face: )

Not skilled enough to help you, but maybe you should create your own topic? (so people would focus on it)