What you can do is use some Roblox built-in CFrame methods.
One I'll be using is vectorToWorldSpace.
local SidePoint = Instance.new('Part',workspace)
local Part = Instance.new('Part',workspace)
SidePoint.Anchored = true
Part.Anchored = true
Part.CFrame = CFrame.new(10,10,10)
Part.Size = Vector3.new(10,10,10)
Part.Transparency = 0.9
Part.BrickColor = BrickColor.new("Bright red")
Points = {
["Top Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(0,1,0)),
["Bottom Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(0,-1,0)),
["Back Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(0,0,1)),
["Front Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(0,0,-1)),
["Right Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(1,0,0)),
["Left Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(-1,0,0))
}
for _,v in pairs(Points) do
steve = SidePoint:Clone()
steve.Parent = workspace
steve.CFrame = CFrame.new(Part.Position + (v*5))
end
Basically, vectorToWorldSpace makes whatever Vector you give it as an argument the new origin of the 3D-grid Roblox goes by. So what we are doing, is taking multiple sides of this 'origin' and basically multiplying it by half the original parts size so it goes right to the border edge of the Part.
Now, to get all the corners, we just need to change up the Vectors a little!
Corners will look like this
Vector3(1,1,1) or V3(1,-1,1)
THERE WILL BE NO 0's
So, let's get the corners this time only:
local SidePoint = Instance.new('Part',workspace)
local Part = Instance.new('Part',workspace)
SidePoint.Anchored = true
Part.Anchored = true
Part.CFrame = CFrame.new(10,10,10)
Part.Size = Vector3.new(10,10,10)
Part.Transparency = 0.9
Part.BrickColor = BrickColor.new("Bright red")
for i = -1,1,2 do
for j = -1,1,2 do
for k = -1,1,2 do
steve = SidePoint:Clone()
steve.Parent = workspace
steve.CFrame = CFrame.new(Part.Position + (Part.CFrame:vectorToWorldSpace(Vector3.new(i,j,k)) * 5))
end
end
end
This will only deal with the numbers, 1 and -1 to ensure we only grab corners.
Dr. Mathematica teaches a bit of it here:
https://www.youtube.com/watch?v=Ys0XCdMA1fE
It gives you a great way of detecting faces!
6 comments
Thanks,for the help but thats not what I really wanted.I wanted the SidePart spawn in the corner of the Part.
Edited.
The edit grabs the corners instead. I put it in the bottom of the post and added more information.
I'm confused so the loops are going 1 and then -1 right?So the how is it getting postive 1 if the it loops are played two times?
Here's what I mean when I run this script: for i = -1,1,2 do for j = -1,1,2 do for k = -1,1,2 do print("i : "..i) print("j : "..j) print("k : "..k) end end end
Ex : It will print "i : -1 j : -1 k : -1" and then "i : -1 j : -1 k : 1 "how did it suddenly go positive and why is the loop played 8 times?