Help connecting two points with Terrain with CFrame

I am making a cave generation system for my game and I am currently trying to optimize it, I figured I could use terrain cylinders instead of a whole bunch of air spheres, however I am struggling to actually have the (air) terrain cylinder connect the two points because I am pretty bad at CFrames.

I have tried to change the order of the CFrames, changing the math.rad() values and yet I can’t get any closer.

Function to place the cylinder (pos1 and pos2 being the positions to connect and size being the radius of the cylinder)

local function generateConnectionCylinder(pos1, pos2, material, size)
	workspace.Terrain:FillCylinder(CFrame.new((pos1+pos2)/2) * CFrame.Angles(math.rad(90), 0, 0) * CFrame.lookAt(pos1, pos2), (pos1-pos2).magnitude, size, material)
end

I don’t think however that the issue is in the main script but instead in the function I gave, if that isn’t the case just let me know if I should give you the cave generation code itself. Thanks in advance

  1. Look at point b from point a
  2. Rotate 90 degrees (clockwise)
  3. Center between points
local function generateConnectionCylinder(a: Vector3, b: Vector3, radius: number, material: Enum.Material)
	local length = (b - a).Magnitude
	local cframe = CFrame.lookAt(a, b) * CFrame.Angles(-math.pi/2, 0, 0) * CFrame.new(0, length/2, 0)
	workspace.Terrain:FillCylinder(cframe, length, radius, material)
end
1 Like

unfortunately this didn’t work, I tried tweaking some values here and there but yet couldn’t really get any closer… I appreciate the effort, tho, so thanks a lot for that

It seems to be working fine on my end. I’ve attached a demo that draws a cylinder between two parts every 10 seconds. You just have to run it and move them around.

CylinderDemo.rbxl (55.4 KB)

1 Like

that’s odd, I’ll try again, hopefully it works that time or something.

Welp that didn’t work when putting that script into my game, the issue must come from where the function is called… I’ll just try troubleshooting a bit more

Alr, thanks a lot for the help! Unfortunately tho I’m not sure if I’ll keep the cylinder system because it just doesn’t really look as good as the old system… If I need to optimize my game tho, I will have WAY less trouble. Thanks a lot for your help!

EDIT: I’m using the cylinder system now, I am really happy with the result and cannot thank you enough!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.