Greetings!
I’m working on a script that creates portals in a semicicle around the player. The portals spawn between a maximum distence from the center(the player), and another smaller semicircle a few studs around the player.
![Radius|592x302]
Thus far I’ve set up a maximum distence from the player, and a minimum around the player.
This is what I’ve got so far.
local RetrievedTreasures = {}
local function CheckIntersection(Object, Treasures)
local Intersects = false
for _,v in pairs(Treasures) do
local radius = 6
local distance = (Object.PrimaryPart.position - v.WepPosCF).Magnitude
if distance < radius then
Intersects = true break
end
end
return Intersects
end
local function CreatePortal()
local Intersect = true
while Intersect do
Portal:SetPrimaryPartCFrame(char:GetPrimaryPartCFrame() + (char:GetPrimaryPartCFrame().RightVector * RandomNumSelection({math.random(-max, -5), math.random(5, max)})) + (char:GetPrimaryPartCFrame().LookVector * -1) + (char:GetPrimaryPartCFrame().UpVector * math.random(0,max)))
Intersect = CheckIntersection(Portal, RetrievedTreasures)
wait()
end
end
CreatePortal()
It works ok, but the problem is that it leaves a gap above the player between the two Z values, and its the whole spawn region for the portals are in a rectangle shape rather then a semicircle.
I’m not very good at explaining things so if theres any questions I’ll try to answer. Thanks in advance.