How could I make a part fill in between two points? (At angles, etc)

I have created the base part of it, the bit that I am stuck on is how to make a part fill in between two points. This is for a sandbox tycoon I am working on, and the wall placement system I am working on will be like Welcome To Bloxburg.


Can you post a picture to make it easier for those wanting to help to understand?

You would essentially click, then drag you mouse and release to build a wall.

@stravant Doesn’t your gapFill plugin use math related to this question? Mind explaining it?

Hmm, I could take a look at the source code of GapFill and try to work it out

Edit: The source code makes hardly any sense. I don’t need all of the arguments the source code takes in, I just need it to make one part that gets positioned and sized perfectly in between the two points to fill the gap.

1 Like

@Coeptus can you help me out, seeing as how you have made this before?

The resulting wall part is going to have:
Height: Equal to the height of the pole (already known)
Thickness: Equal to the pole diameter presumable (already known)
Width: Equal to the distance between poles (pole1.Position - pole2.Position).Magnitude
WallPosition: Halfway between the poles: pole1.Position + 0.5*(pole2.Position - pole1.Position)

Orientation: Orthogonal to both the world vertical (y-axis) and the vector from pole1 to pole2. To calculate this, you can do (pole1.Position - pole2.Position).Unit:Cross(,1,0)). If I got the signs right, that should be the lookVector for your wall. Even if I got the sign wrong, it will still work if you wall is smooth plastic and there is no distinction between the inside and outside :grin: This orientation assumes that the big flat faces of your wall are the Front and Back faces of the part.

Wall CFrame =, WallPosition + lookVector)

That CFrame constructor which takes two vectors gives you a CFrame that is at the position given by the first vector, and facing the position given by the second vector.

Note that this constructor works fine when the lookVector is in the X-Z plane, but it will not work as expected if you try to re-use this code for floors or a roof. The reason for this is that I believe this constructor was probably intended for the camera or other things that are “upright” in the world, and it picks the orientation for you. If the lookVector is near the y-axis (what the constructor considers UP), it will give you basically an arbitrarily oriented part. So you can use it for floors that face upward, you just have to do the calculations like you would for a wall and then flip the part 90 degrees.