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:

01--[[
02A _ _ _ _ _ _ _
03_ _ _ _ _ _ _ _
04_ _ _ _ _ _ _ _
05_ _ _ _ _ _ _ _
06_ _ _ _ _ _ _ _
07_ _ _ _ _ _ _ _
08_ _ _ _ _ _ _ _
09_ _ _ _ _ _ _ B
10]]

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

Let C be the new part.

01--[[
02A _ _ _ _ _ _ _
03_ C _ _ _ _ _ _
04_ _ C _ _ _ _ _
05_ _ _ C _ _ _ _
06_ _ _ _ C _ _ _
07_ _ _ _ _ C _ _
08_ _ _ _ _ _ C _
09_ _ _ _ _ _ _ B
10]]

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

1a = Vector3.new(20, 10, 40)
2b = 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.

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

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

1local length = (a - b).magnitude
2p.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:

1local middle = (a + b) / 2

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

1p.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