No physics rod module

The no physics rod module.

Basically you want to connect 2 parts with a cylinder and tried RodConstraints but they had physics and breaking the system? This module is literally made for that.

local runService = game:GetService("RunService")
local MaterialService = game:GetService("MaterialService")
local module = {}

function module.connectParts(part1, part2, thickness, name, parent)  -- can be adjustable for your needs
	if not part1 or not part2 then
		warn("Invalid parts or attachments")
		return
	end

	local pos1, pos2
	if part1:IsA("Attachment") and part2:IsA("Attachment") then
		pos1 = part1.WorldPosition
		pos2 = part2.WorldPosition
	elseif part1:IsA("Part") and part2:IsA("Part") then
		pos1 = part1.Position
		pos2 = part2.Position
	else
		if part1:IsA("Attachment") then
			pos1 = part1.WorldPosition
			pos2 = part2.Position
		elseif part2:IsA("Attachment") then
			pos1 = part1.Position
			pos2 = part2.WorldPosition
		end
	end

	local cylinder = Instance.new("Part")
	cylinder.Shape = Enum.PartType.Cylinder
	cylinder.Name = name
	cylinder.Anchored = true
	cylinder.CanCollide = false
	cylinder.Size = Vector3.new((pos2 - pos1).magnitude, thickness, thickness)
	cylinder.Color = Color3.fromRGB(176, 120, 88)
	cylinder.Material = Enum.Material.SmoothPlastic 
 	cylinder.Parent = parent 

	local mesh = Instance.new("SpecialMesh") 
	mesh.MeshType = Enum.MeshType.Cylinder
	mesh.Parent = cylinder

	cylinder.CFrame = CFrame.new((pos1 + pos2) / 2, pos2) * CFrame.Angles(0, math.pi/2, 0)

	local connection

	connection = runService.Heartbeat:Connect(function()

		if part1:IsA("Attachment") and part2:IsA("Attachment") then
			pos1 = part1.WorldPosition
			pos2 = part2.WorldPosition
		elseif part1:IsA("Part") and part2:IsA("Part") then
			pos1 = part1.Position
			pos2 = part2.Position
		else
			if part1:IsA("Attachment") then
				pos1 = part1.WorldPosition
				pos2 = part2.Position
			elseif part2:IsA("Attachment") then
				pos1 = part1.Position
				pos2 = part2.WorldPosition
			end
		end

		local newDistance = (pos2 - pos1).magnitude
		cylinder.Size = Vector3.new(newDistance, thickness, thickness) 
		cylinder.Position = (pos1 + pos2) / 2
		cylinder.CFrame = CFrame.new((pos1 + pos2) / 2, pos2) * CFrame.Angles(0, math.pi/2, 0)
	end)

	return cylinder, connection
end

function module.breakConnection(connection, cylinder)
	if connection then
		connection:Disconnect()
		cylinder:Destroy()
	end
end

return module

USAGE:

local p1, p2 = script.Parent.Part1, script.Parent.Part
local m = require(game.ReplicatedStorage.NoPhysicsRodModule)

local Rod, Connection = m.connectParts(p1, p2, 0.1, "Connection", script.Parent) -- to create the Rod
m.breakConnection(Connection, Rod) -- To Destroy the connection

This module lets you connect 2 parts without any physics directly. Both Client and Server Side support with RunService.Heartbeat. Works both Part.Position and Part.Attachment. Thank you!

(sorry if the topic is made badly cus my english is kind of bad)

4 Likes

Any toughts on the idea ?

chars lim

Why are you using SpecialMesh? You should be using:

cylinder.Shape = Enum.PartType.Cylinder

SpecialMesh is way less optimized, and it isn’t occlusion culled!

Ahh yeah man thanks for the info :pray: . I just never use other types of Shapes so I forgot that propertys existance, I only use Blocks