How to Generate a Part to Elongate Between Two Other Parts


  • 0_1523305879198_Captureq.JPG

    Hi,

    This is my first tutorial and I wanted to show something simple, but cool. This script basically creates a part that "stretches" between two points, which themselves are parts. Essentially, you can create two parts with any position you choose (by changing the Vector3 position for part1 and part2, or in the image, line 2 and line 9) and a part in the middle will conform to those changes. It's useful if you want to randomly generate pathways that you can walk on, or just for decoration purposes.

    Line 1 to line 13:
    Create two different parts in any location you choose. In this example, the parts are placed in a model, but you could just add it into the Workspace. Make sure that the parts are anchored so they don't fall to the ground. I would also not make them collide-able.

    Line 15:
    This variable calculates the distance between two positions, in this case, part1 and part2.

    Line 17-20:
    Now, you want to find the midpoint (xm, ym, zm) of the line that intersects between two part positions, in 3D space. You can add each of the X, Y, and Z coordinates for part1 and part2 individually, then divide each by 2.

    Line 21-28:
    Finally, create a part at a position at the midpoint coordinates calculated from the previous lines. For the size, you want to make the part "stretch" between the two points. You can make the Z argument the magnitude, or length of the line between part1 and part2. Finally, the part is elongated out, but it is not oriented to face any of the two parts. To orient the midpoint part properly, get the current position of itself, and then direct it to face towards a specific position, in this case the position of part1 or part2.

    I plan to add more tutorials in the future. If there are any mistakes or if you have improvements, please post below, thanks.

    Houlardy


  • best way to get the cframe and position between the part is:

    cf = CFrame.new
    c = Part1.CFrame
    p = Part.Position
    partm.CFrame = c * cf(c:inverse() * p, p)
    

    i think anyway

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.