How to replicate the swinging in this video?

https://gyazo.com/ab725876183652d36daf3e2f8df97305
How would I replicate/script the swinging of the green objects in this video?

2 Likes

You can do it via roblox physics engine or manually.

The general name for the swinging motion is pendelum.

This tutorial is a good starting place although the math is a bit off.

For a more accurate and realistic math explanation:

1 Like

Thanks. I used the physics in the first link. However, I’ve run into an issue with the orientation of my model. I want it so that the chain always faces the fixed point/position. Do you think you could help?
What I want:


My code:

local theta = 5
local angVel = 0

game:GetService("RunService").Heartbeat:Connect(function(dt)
	for _, broccoliSwing: Model in broccoliSwings:GetChildren() do
		if not broccoliSwing:IsA("Model") then continue end
		local bob = bobs[broccoliSwing:GetAttribute("Num")]
		local fixedPoint = fixedPoints[broccoliSwing:GetAttribute("Num")]
		local length = (fixedPoint.Position - bob.Position).Magnitude
		local XArc = length * math.sin(theta)
		local YArc = length * math.cos(theta)
		bob.CFrame = CFrame.new(Vector3.new(XArc, YArc, 0)) + fixedPoint.CFrame.Position
		broccoliSwing:PivotTo(bob.CFrame)
		angVel = angVel + (0.0005*math.sin(theta))
		theta = theta + angVel
	end
end)

1 Like

–Bump-- Minimum characters needed

theres two ways to handle this, you could simulate it as dthecoolest stated prior, or you can have set CFrame values of the primary part of the assembly you have, that fixed point, and use TweenService or Interpolation to ease between the preset swing CFrames you wish

A super easy way is using TweenService, like Ziraun described.

set pivot to one part’s end, then create while loop that rotates it from one point to other, use lerping with some math to achieve this effect

This also worked! The only issue is there is a delay when going from position to position. How do you think I could smooth it out?

Can you show us the script you are using?

two ways, you could either make it a looping script that waits for one tween to end using Tween.Completed:Wait() or you can loop it so that it does the other tween a split second before the first one is supposed to end