Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I get the area between multiple parts?

Asked by
sad_eyez 162
5 years ago
Edited 5 years ago

I have tried quite a few methods, I am trying to get the area between multiple parts so the item I place down can only be placed n that area, and not on the outside of that area.

Here is an image of the area: pasteboard.co/HVrdQ2a.png

local m = {}

-- Priority Variables
local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local rs = game:GetService("ReplicatedStorage")
local furniture = rs["Furniture"]
local remotes = rs["Remotes"]
local confrimPlacement = remotes["ConfirmPlacement"]

-- Secondary Variables
local studio = workspace:WaitForChild("Harbour Studio")
local studioFurniture = studio["Furniture"]
local owner = studio["Owner"]

--Model Placement Varibles
local plr
local mouse
local itemsFrame
local finished
local node
local preview
local pp
local selection
local canPlace
local rot = 0
local placing



function previewItem()
    if (placing == false) then
        return
    end

    local allNodes = studio["Nodes"]:GetChildren()
    for _,n in next, allNodes do
        node = n
    end

        if (owner.Value == plr.Name) and (pp.Position - node.Size).magnitude < (node.Position - pp.Size).magnitude then
            selection.Color3 = Color3.fromRGB(0,155,0)
            canPlace = true
        else
            selection.Color3 = Color3.fromRGB(155,0,0)
            canPlace = false
        end
        local angle = CFrame.fromEulerAnglesXYZ(0,math.rad(rot),0)
        local vec = Vector3.new(0,preview.PrimaryPart.Size.Y/2,0)
        local cf = CFrame.new(mouse.Hit.p+vec)*angle
        preview:SetPrimaryPartCFrame(cf)
end



function m.start(p, modelName, frame, fin)
    plr = p
    itemsFrame = frame
    finished = fin
    itemsFrame.Visible = false
    finished.Visible = false
    mouse = plr:GetMouse()
    --node = studio["Node1"]

    preview = furniture[modelName]:Clone()
    preview.Parent = workspace
    pp = preview.PrimaryPart
    selection = Instance.new("SelectionBox", workspace)
    selection.LineThickness = 0.05
    selection.Adornee = pp
    mouse.TargetFilter = preview
    for i,p in next, preview:GetChildren() do
        if not (p.Name == "Hitbox") then
            p.Transparency = 0.5
            p.CanCollide = false
        end
    end
    placing = true
    runService.RenderStepped:Connect(previewItem)
end

function m.cancel()
    if (preview) then
        placing = false
        preview:Destroy()
        selection:Destroy()
        plr = nil
        mouse = nil
        node = nil
        mag = nil
        preview = nil
        pp = nil
        selection = nil
        canPlace = nil
        rot = 0
        itemsFrame.Visible = true
        itemsFrame = nil
        finished.Visible = true
        finished = nil
    end
end

function m.rotate()
    if (preview) then
        rot = rot +1
        preview:SetPrimaryPartCFrame(preview.PrimaryPart.CFrame*CFrame.fromEulerAnglesXYZ(0,math.rad(rot),0))
    end
end


function m.place()
    if (preview) and (placing == true) and (canPlace == true) then
        placing = false
        confrimPlacement:FireServer(preview.Name, preview:GetPrimaryPartCFrame())
    end
end

return m

0
magnitude Sorukan 240 — 5y
0
I don't really know how to use it sad_eyez 162 — 5y
0
maybe region3 ihatecars100 502 — 5y
0
Hey -- it seems the other answers haven't looked at the image you provided. Are you looking for surface area or complex volume? (surface area or cubic studs inside of your highlighted area) SummerEquinox 643 — 5y
0
Not sure, I just want to be able to check to see if the object I am placing is between the area I have highlighted. sad_eyez 162 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

I think you mean magnitude. You can use magnitude to find the distance between two objects. Here's an example:

local Part1 = workspace.Part1
local Part2 = workspace.Part2

local magnitude = (Part.Position - Part2.Position).magnitude

Resources:

Magnitude

Accept and upvote if this helped!

1
u stole this from wiki HappyTimIsHim 652 — 5y
0
no i didnt.. there's just one way to get magnitude like this bc its a formula. just like there's only one way to solve the area of a rectangle Gey4Jesus69 2705 — 5y
0
I updated my post, I still don't understand it really, I ain't good with math sad_eyez 162 — 5y
Ad
Log in to vote
0
Answered by
Sorukan 240 Moderation Voter
5 years ago

Magnitude is basically the distance between 2 points, in your case it's the distance between your 2 parts. The distance is measured in studs so if you were to do

local Part1 = game.workspace.Part1
local Part2 = game.workspace.Part2

local distance = (Part1.Position - Part2.Position).magnitude -- this finds the distance between the 2 parts

wait(3)
print("distance")

What printing the distance will do is tell you the exact amount of studs between Part1 and Part2. You can do much more with it rather than just printing such as finding the distance between a part and a player's torso, then if the distance is less than or greater than a certain amount of studs, you can do something.

Answer this question