Make objects push away each other when they are too close

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Im trying to make a troop of plane that flies to the target point.
    to make them not to clip with each other, i have to make them push each other away when they collide.

  2. What is the issue? Include screenshots / videos if possible!
    i managed to implement it and it works fine but it was too laggy. My method was detecting parts nearby by using workspace:GetPartBoundInRadius(), then calculating the strength accordingly to the distance.

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    i couldn’t find out any great way to decrease lag. so please help.

This is something i want to achieve. see those tiny triangles following the cursor, but when they get too close, they push each other away creating perfect gap between each other.

Get parts in bound is a too laggy method.

You can check the magnitude (distance) of each troop!

With the following math:

local troops = {} -- assume you have troops in this array
local targetDistance = 3 -- change it to test 

--takes an array of troops, and gives an array of troops too close
local function GetMagnitude(array,object)
 local magnitudes = {}
 for _,v in pairs(troops) do
   if(v.Vector - object.Vector).Magnitude < targetDistance then --if too close
   magnitudes[v] = true
  end
  end
 return magnitudes
end

Using this function or similar (im on phone so it may not be syntax correct) would be less laggier, just know that the more troops, the more laggier it becomes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.