I have 2 players in a Linear setting where they face each other in a straight line and can only move forwards and backwards with custom buttons I’ve made. How can I prevent them from hitting each other because if they do they go above one another and its a mess. I use BodyVelocity for the movements because even though its deprecated it is more useful that LinearForce which I’ve tried using to push them back when about to meet but it doesnt really work
local function Distancer(plr, db)
local char
if plr.Character then
db = false
char = plr.Character
local veloc = Instance.new("LinearVelocity", char)
veloc.Attachment0 = char.HumanoidRootPart.RootRigAttachment
veloc.VectorVelocity = (char:GetPivot().LookVector*(-10))*10
veloc.MaxForce = 5000
veloc.RelativeTo = Enum.ActuatorRelativeTo.World
coroutine.wrap(function()
task.wait(0.2)
veloc:Destroy()
db = true
end)()
end
end
local radius = 7
local db = false
while task.wait(.1) do
local BluePos = BluePlayer.Character.HumanoidRootPart.Position
local RedPos = RedPlayer.Character.HumanoidRootPart.Position
local currentRadius = BluePlayer:DistanceFromCharacter(RedPos)
if not db and radius > 0 and currentRadius <= radius then
Distancer(BluePlayer, db)
Distancer(RedPlayer, db)
end
end