I made this rope swinging system but it’s a bit buggy.
I’ve factored in the camera’s cframe’s look vector and used that to determine the direction, which worked except for this:
I thought it was to do with the shorter sides of rectangles, but for some reason it doesn’t work on squares for one side too?
I have no idea why this is happening and it’s really odd behaviour, here’s my code:
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
local origin = hrp.Position
local direction = mouse.Hit.Position - origin
local raycast = workspace:Raycast(origin, direction, params)
if raycast then
if not (raycast.Normal == Vector3.new(0,-1,0)) or deb then
return
end
local rope = Instance.new("RopeConstraint")
rope.Thickness = .2
rope.Color = BrickColor.new("Pink")
rope.Visible = true
hrp.Anchored = true
local attachment0, attachment1 = Instance.new("Attachment", hrp), Instance.new("Attachment", raycast.Instance)
attachment0.WorldPosition = hrp.Position
attachment1.WorldPosition = raycast.Position
rope.Attachment0 = attachment0
rope.Attachment1 = attachment1
rope.Length = (attachment0.WorldPosition - attachment1.WorldPosition).Magnitude
rope.Parent = workspace
local Origin = raycast.Instance
local Bob = hrp
local Length = (Origin.Position - Bob.Position).Magnitude
local theta = math.rad(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) * (workspace.CurrentCamera.CFrame.LookVector * Vector3.new(-2, 0, -2) + Vector3.new(0,1,0)), Vector3.new()) +
Origin.CFrame.Position, 0.05)
angVel = (angVel + (0.01*math.sin(theta)))
theta = theta + angVel
end
deb = true
conn = game:GetService("RunService").Heartbeat:Connect(Compute)
task.wait(.8)
hrp.Anchored = false
deb = false
if conn then
conn:Disconnect()
end
rope:Destroy()
I took a pendulum swinging mechanism code of off a post and I’ve tried to make it work, and it works except for that one problem
Can somebody please help
This is probably the main part of the code you’ll need to look at
Bob.CFrame = Bob.CFrame:Lerp(CFrame.new(Vector3.new(XArc , YArc, 0) * (workspace.CurrentCamera.CFrame.LookVector * Vector3.new(-2, 0, -2) + Vector3.new(0,1,0)), Vector3.new()) +
Origin.CFrame.Position, 0.05)