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

Part Point Extension?

Asked by
Scarious 243 Moderation Voter
8 years ago
Edited 8 years ago

So, imagine you have 2 points...

pointa, and pointb.

Here is the graph:

--[[
A _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ B
]]

Now, I want to create a part that extends the length of the distance between pointa and pointb.

Let C be the new part.

--[[
A _ _ _ _ _ _ _
_ C _ _ _ _ _ _
_ _ C _ _ _ _ _
_ _ _ C _ _ _ _
_ _ _ _ C _ _ _
_ _ _ _ _ C _ _
_ _ _ _ _ _ C _
_ _ _ _ _ _ _ B
]]

How would I go about doing this? I've thought about using lookvector, but I haven't found a decent way to learn how to do this... I can find almost nothing on it.

Help?

1 answer

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago
Edited 8 years ago

Say a and b are two positions in the world (they are Vector3s).

a = Vector3.new(20, 10, 40)
b = Vector3.new(50, 20, 10)

We want to make a part that stretches between them. Let's say it's 2x2xlength, with the front face being centered on b and the back face being centered on a.

local p = Instance.new("Part", workspace)
p.Anchored = true

length, which is just the distance between a and b, is easily computed using magnitude:

local length = (a - b).magnitude
p.Size = Vector3.new(2, 2, length)

If the back is at a and the front is at b, the middle is exactly half way across:

local middle = (a + b) / 2

Using the CFrame.new(lookingFrom, lookingAt) constructor, we can easily make the right CFrame for p:

p.CFrame = CFrame.new(middle, b)
0
Trying it now, I guess I need to brush up on my CFraming skills. ty. Scarious 243 — 8y
0
Worked like a charm. Scarious 243 — 8y
Ad

Answer this question