Bridge Physics System

I am trying to make a bridge system. The idea is you place down planks that allow you to cross a gap. Only issue is one long part will allow you to pass. My goal is to make a system that will make the bridge collapse if too much weight (such as a person) stands on top of the bridge. Adding more support will make it strong enough to hold you.
See video:

This is my current code for that plank system you saw. I plan on changing this to adapt to the new system of course:

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
UserInputService = game:GetService("UserInputService")

local secondPoint = false

local function MakePlank(StartPos, EndPos, startPoint, endPoint)
	
	local distance = math.sqrt((StartPos.X - EndPos.X)^2 + (StartPos.Y - EndPos.Y)^2 + (StartPos.Z - EndPos.Z)^2)
	local center = distance/2
	print(distance)
	
	local plank = Instance.new("Part")
	plank.Name = "Plank"
	plank.Anchored = true
	
	plank.Size = Vector3.new(1,0.1,distance)
	plank.Position = Vector3.new((StartPos.X + EndPos.X)/2, (StartPos.Y + EndPos.Y)/2, (StartPos.Z + EndPos.Z)/2)
	plank.CFrame = CFrame.new(plank.CFrame.Position, EndPos)
	
	plank.Parent = workspace.PlankAspects.Planks
end

UserInputService.InputEnded:Connect(function(input) --MakePoints
	if secondPoint == false then
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			secondPoint = true
			StartPos = Mouse.Hit.Position
			print(StartPos)
			

			if workspace.PlankAspects.Points:FindFirstChild("EndPoint") then
				workspace.PlankAspects.Points:FindFirstChild("EndPoint"):Destroy()
				workspace.PlankAspects.Points:FindFirstChild("StartPoint"):Destroy()
			end

			--make Point
			startPoint = Instance.new("Part")
			startPoint.Size = Vector3.new(0.5, 0.5, 0.5)
			startPoint.Position = StartPos
			startPoint.Shape = Enum.PartType.Ball
			startPoint.Color = Color3.new(0, 1, 0)
			startPoint.Anchored = true
			startPoint.Name = "StartPoint"
			startPoint.Parent = workspace.PlankAspects.Points
		end
	else
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			secondPoint = false
			EndPos = Mouse.Hit.Position
			print(EndPos)



			--make Point
			endPoint = Instance.new("Part")
			endPoint.Size = Vector3.new(0.5, 0.5, 0.5)
			endPoint.Position = EndPos
			endPoint.Shape = Enum.PartType.Ball
			endPoint.Color = Color3.new(1, 0, 0)
			endPoint.Anchored = true
			endPoint.Name = "EndPoint"
			endPoint.Parent = workspace.PlankAspects.Points
			
			MakePlank(StartPos, EndPos, startPoint, endPoint)
		end
	end
end)


:]

1 Like

One way is use BasePart:GetTouchingParts() to get a table of all BaseParts touching that part, add the mass of each part in the table, and if that mass is more than the weight limit you set, then you can do a number of things:

• Replace the old bridge with a new one that has multiple segments, then BreakJoints() (or delete Constraints you created).

• Make the script that makes bridges make the bridges have multiple segments from the start, and make them fall if there’s too much weight


Just brainstorming, these are what comes to mind first. Hope this helps!

1 Like

To be able to simulate this you need a way to find the force on the bridge elements, which would let you also calculate the force on the joints between them. I don’t know a way to do this as I don’t think theres a direct way to get physics forces from the engine. There might be ways to work around this by making your own simpler physics system and translating the players weight into that somehow, such as by choosing one point on one part and assuming that it supports the players full weight.

1 Like