Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function SquaredDistance(a,b)
- return (a -b):LengthSqr()
- end
- local function FindClosest(ent,tEnts)
- local pos = ent:GetPos()
- local dClosest = math.huge
- local entClosest
- for _,entTgt in ipairs(tEnts) do
- local posTgt = entTgt:GetPos()
- local dSqr = SquaredDistance(pos,posTgt)
- if(dSqr < dClosest) then
- dClosest = dSqr
- entClosest = entTgt
- end
- end
- local dist = math.sqrt(dClosest) // ACTUAL DISTANCE
- return entClosest,dist
- end
- local entClosest = FindClosest(player.GetAll()[1],ents.GetAll())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement