I made a pendulum swinging mechanism for the player by taking code off of this post and I managed to make it do this
But when I do it on a part rotated differently, it goes the same direction which I don’t want
I’m not really that good at trigonometry, so how do I make this pendulum involving the character swing according to the part’s orientation
local Origin = raycast.Instance
local Bob = hrp
local Length = (Origin.Position - Bob.Position).Magnitude
local theta = 45
local angVel = 0
local function Compute()
local XArc = Length * math.sin(theta)
local YArc = Length * math.cos(theta)
--local ZArc = Length * math.rad(theta)
Bob.CFrame = Bob.CFrame:Lerp(CFrame.new(Vector3.new(XArc , YArc, 0) , Vector3.new()) +
Origin.CFrame.Position, 0.05)
angVel = (angVel + (0.01*math.sin(theta)))
theta = theta + angVel
end
deb = true
local playerdirection = hrp.CFrame.LookVector
if -playerdirection.Z > 0 then
print(theta)
theta = -theta
end
conn = game:GetService("RunService").Heartbeat:Connect(Compute)
task.wait(.8)
hrp.Anchored = false
deb = false
if conn then
conn:Disconnect()
end
rope:Destroy()