I’m working on a pendulum effect in Roblox and am trying to make it swing smoothly between -180 and 180 degrees. I’m using TweenService to create the back-and-forth motion, but I want to ensure the pendulum rotates correctly in both directions without manually creating multiple tweens just like in Obby But You’re On a Bike.
--[Services]--
local TweenService = game:GetService("TweenService")
--[Tween Information]--
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 0) -- Looping indefinitely with reversing enabled
--[Create Tween]--
local targetPart = script.Parent
local Tween = TweenService:Create(targetPart, TweenInfo, {CFrame = targetPart.CFrame * CFrame.Angles(0, 0, math.rad(180))})
--[Play Tween]--
Tween:Play()
I set the reverses property to true and the repeatCount to -1 to make it go back and forth, but I’m unsure if this is the best approach for achieving smooth swinging. The goal is to have the part rotate indefinitely from -180 to 180.
The pendulum uses Rod and Hinge constraints because, previously, I tried using Rope and, sadly, it didn’t work. This was the best approach that I could replicate just like in the game I mentioned in my topic, but something is not going right with the degrees
I think its cuz the rotation is 180 where you are looking for 90 degrees to go opposite, if the pendulum starts at 45 degrees. Also, it should be in a local script to be more smooth for the players.
if your finding them go wonky try using welds and setting the other objects than that white cylinder unanchored. see if the cylinder alone starts to rotate correctly, it might be a problem with the build.
Rods pivot at the Attachments so the ball will rotate around the attachments.
Just use a long Cylinder Part as your ‘rope’ and weld it and the ball to the pivot Part. Tween the Anchored pivot Part with your script.
Also try 179 degrees. If you use exactly 180 it may sometimes go the other direction around if it goes .0000000001 degrees past the end value. The engine sees that as the shortest number of degrees to get to the goal.
local ts = game:GetService("TweenService")
local info = TweenInfo.new(2,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,-1,true,0)
local value = Instance.new("NumberValue")
value.Value = -90
local cf = workspace.Anchor.CFrame:ToObjectSpace(workspace.Bob.CFrame)
ts:Create(value,info,{Value = 90}):Play()
value.Changed:Connect(function()
workspace.Bob.CFrame = workspace.Anchor.CFrame*CFrame.Angles(math.rad(value.Value),0,0)*cf
end)
Why are you telling that to me? It’s not my job to do everything for the OP like they are a child. They could do it themselves. My job is to just give them the concept. Like every forum member should. It’s in the rules themselves.