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 10 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)

01SidePoint = Instance.new('Part',game.Workspace)
02Part = Instance.new('Part',game.Workspace)
03 
04--I'm trying to spawn a sidepoint on the points of the part
05 
06SidePoint.Anchored = true
07Part.Anchored = true
08 
09Part.CFrame  = CFrame.new(10,10,10)
10Part.Size  = Vector3.new(10,10,10)
11Part.Transparency = 0.9
12Part.BrickColor = BrickColor.new("Bright red")
13 
14Points = {
15    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
16    CFrame.new()--How would I get the other point on top of the 1st point?
17    }
18 
19SidePoint.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 10 years ago

What you can do is use some Roblox built-in CFrame methods.

One I'll be using is vectorToWorldSpace.

01local SidePoint = Instance.new('Part',workspace)
02local Part = Instance.new('Part',workspace)
03 
04SidePoint.Anchored = true
05Part.Anchored = true
06 
07Part.CFrame = CFrame.new(10,10,10)
08Part.Size = Vector3.new(10,10,10)
09Part.Transparency = 0.9
10Part.BrickColor = BrickColor.new("Bright red")
11 
12Points = {
13["Top Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(0,1,0)),
14["Bottom Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(0,-1,0)),
15["Back Face"] = Part.CFrame:vectorToWorldSpace(Vector3.new(0,0,1)),
View all 25 lines...

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:

01local SidePoint = Instance.new('Part',workspace)
02local Part = Instance.new('Part',workspace)
03 
04SidePoint.Anchored = true
05Part.Anchored = true
06 
07Part.CFrame = CFrame.new(10,10,10)
08Part.Size = Vector3.new(10,10,10)
09Part.Transparency = 0.9
10Part.BrickColor = BrickColor.new("Bright red")
11 
12for i = -1,1,2 do
13    for j = -1,1,2 do
14        for k = -1,1,2 do
15            steve = SidePoint:Clone()
16            steve.Parent = workspace
17            steve.CFrame = CFrame.new(Part.Position + (Part.CFrame:vectorToWorldSpace(Vector3.new(i,j,k)) * 5))
18        end
19    end
20end

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 — 10y
1
Edited. DigitalVeer 1473 — 10y
1
The edit grabs the corners instead. I put it in the bottom of the post and added more information. DigitalVeer 1473 — 10y
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 — 10y
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 — 10y
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 — 10y
Ad

Answer this question