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?
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 2
x2
xlength
, 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)