I'm trying to make a part named "SidePoint" spawn on all four points of the a Part but, I have no idea how to get points of this part.
I already know a parts position is defined in the middle(I don't really know,I forgot)
SidePoint = Instance.new('Part',game.Workspace) Part = Instance.new('Part',game.Workspace) --I'm trying to spawn a sidepoint on the points of the part 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 = { CFrame.new(math.floor(Part.CFrame.X/2),math.floor(Part.CFrame.Y/2),math.floor(Part.CFrame.Z/2)),--1st Point I don't know why I divided it but,it worked CFrame.new()--How would I get the other point on top of the 1st point? } SidePoint.CFrame = Points[1]
Here is a a example of what I mean: http://imgur.com/wfqFElY
How do I get all four points of this part?
Will I have to use trigonometry?
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
Dr. Mathematica teaches a bit of it here:
https://www.youtube.com/watch?v=Ys0XCdMA1fE
It gives you a great way of detecting faces!