So, imagine you have 2 points...
pointa, and pointb.
Here is the graph:
01 | --[[ |
02 | A _ _ _ _ _ _ _ |
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 | --[[ |
02 | A _ _ _ _ _ _ _ |
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?
Say a
and b
are two positions in the world (they are Vector3s).
1 | a = Vector 3. new( 20 , 10 , 40 ) |
2 | b = Vector 3. 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
.
1 | local p = Instance.new( "Part" , workspace) |
2 | p.Anchored = true |
length
, which is just the distance between a
and b
, is easily computed using magnitude:
1 | local length = (a - b).magnitude |
2 | p.Size = Vector 3. new( 2 , 2 , length) |
If the back is at a
and the front is at b
, the middle is exactly half way across:
1 | local middle = (a + b) / 2 |
Using the CFrame.new(lookingFrom, lookingAt)
constructor, we can easily make the right CFrame for p
:
1 | p.CFrame = CFrame.new(middle, b) |