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

Help with CFrame or Vector3?

Asked by 9 years ago

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?

1 answer

Log in to vote
3
Answered by 9 years ago

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!

0
Thanks,for the help but thats not what I really wanted.I wanted the SidePart spawn in the corner of the Part. kevinnight45 550 — 9y
1
Edited. DigitalVeer 1473 — 9y
1
The edit grabs the corners instead. I put it in the bottom of the post and added more information. DigitalVeer 1473 — 9y
0
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?  kevinnight45 550 — 9y
View all comments (2 more)
0
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 kevinnight45 550 — 9y
0
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? kevinnight45 550 — 9y
Ad

Answer this question