Instances clipping into eachother

Hi, I have a problem where my units are clipping into each other fighting for the same space. I’m using ‘move away from’ to keep the units separate, but it seems that when they are bunched up too close they somewhat teleport around each other.

The units are also using the pathfinding behavior.

The effect can be seen in this video:

I guess the idea would be to prevent them from getting close enough to each other for this to happen somehow.

1 Like

Hello I’m not sure if it would help but you can use physics as static objects you that they won’t get into each other. Just an advice. Otherwise I need to see your code.

I did hear there was an issue where pathfinding and physics won’t work together properly, which I’ve seen myself, the units won’t move at all.

Maybe you want to disable the “move away from” at certain times? Or maybe disable the pathfinding for some units while others move through?
What would you like to happen?

I guess the best outcome would be for the units to be completely impassable by each other. Not occupy each others space, ever. In a way where they don’t teleport and clip through each other. It looks like they are trying to relocate themselves to a different side of the collision. I’ve had situations where they will teleport through a static wall collision, in much the same way.

So very probably not temporarily disable move away from, disabling path finding might work. It would be good if they can’t even get into the range of each other where this clipping teleporting thing is possible.

Mind if I ping this? I’m still having issues here.

I think a workable solution might be to have collisions disabled if a large amount of units are in the same area, is there a way to do an instance count in a radius or something? So if instance count AllyUnits is +4 within a distance of 5 px, DO NOT move away from.

Someone in another topic recommended using a tracker object for the pathfinding, and a physics behavior for the units, to handle the collisions.
You should give it a try, but physics is more resource-intensive, so it might get laggy if you have too many units.

Regarding your idea of checking instances in a radius, my guess is that you would create an array for each unit, store in it the ID of each unit close, and remove the ID when far, and when the number of children of the array exceeds 4, do what you want. Possibly, you’ll get a headache from that one. :grin:

Good luck.

1 Like

Oh thanks, I quite like that first idea and really hope I don’t have to resort to the second. If I get it working I’ll post my solution here so other people can use the solution if I find one. I’m not expecting this to be easy, so it takes as long as it takes.

One idea I had and will be trying today is to have a separate collision object but then instead of having units XY equal to the collision, have the unit move towards the collision, so the collision will do the jumping around thing like normal, but the visual unit will just move towards the position of the collision in a natural way using it’s movement speed. The units will pass each other, be in each other’s personal space, but it will at least look way more natural.

Initial tests show that this is kind of working. The sprites shudder when they are fighting for the same space, makes sense they’re moving into the space they’re targeting and then they’re pushed back each frame. This method hits performance hard though, I can only have about 80 units per scene before the frames start to drop. Which might be fine for something smaller scale.