Need help creating a script that connects 2 spheres with a cylinder and as spheres change their position, the cylinder changes its length to connect the 2 spheres including changing its direction if needed
For example
From this:
To this
^^^ The cylinder increases its length.
How would I approach this and would I use welds/constraint welds?
Also with the Touched event, is there a way to get the position of where an object is being Touched?
You could do:
local s1 = workspace.Point1
local s2 = workspace.Point2
local Cyl = workspace.Cylinder
local newCylCFrame = CFrame.lookAt(s1.Position,s2.Position):PointToWorldSpace(Vector3.new(0,0,(s2.Position-s1.Position).Magnitude/2))
Cyl.CFrame = newCylCFrame
And thats about it, you might need to rotate around the vector3 components though
Unable to assign property CFrame. CoordinateFrame expected, got Vector3 - Server - Script:6
I’ve got this so far
```lua
local ball1 = script.Parent.Ball1
local ball2 = script.Parent.Ball2
local cylinder = script.Parent.Cylinder
local distance = math.abs((ball1.Position - ball2.Position).Magnitude)
cylinder.CFrame = CFrame.lookAt(ball1.Position, ball2.Position) * CFrame.new(0, 0, distance / 2) * CFrame.Angles(0, math.rad(90), 0)
while true do
ball2.CFrame *= CFrame.new(-5, 0, 0)
distance = math.abs((ball1.Position - ball2.Position).Magnitude)
cylinder.CFrame = CFrame.lookAt(ball1.Position, ball2.Position) * CFrame.new(0, 0, distance / 2) * CFrame.Angles(0, math.rad(90), 0)
cylinder.Size = Vector3.new(distance, cylinder.Size.Y, cylinder.Size.Z)
task.wait(1)
end