You're right! The issue is that when you attach to an anchored part (like a building), the rope keeps you tethered at a fixed distance, preventing you from swinging freely. This happens because RopeConstraint acts like a rigid tether when both attachment points can't move relative to each other.
The solution is to use a BallSocketConstraint instead of a RopeConstraint when swinging. This allows free rotation around the attachment point while maintaining the connection. Here's the fixed version:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
-- Settings
local MAX_SWING_DISTANCE = 200
local SWING_BOOST = 40
local CLIMB_SPEED = 45
local MIN_ROPE_LENGTH = 5
local HAND_OFFSET_DISTANCE = 2.5
local GRAB_DISTANCE = 10
local PULL_SPEED = 30
-- State variables
local isSwinging = false
local isClimbing = false
local isPulling = false
local swingConstraint = nil -- Changed from swingRope
local swingAttachment = nil
local grabbedObject = nil
local swingPart = nil
local webBeam = nil -- Visual representation of the web
-- IK Variables
local ikControl = nil
local handTargetAttachment = nil
-- R15 Limb Definitions
local UPPER_ARM = character:FindFirstChild("RightUpperArm")
local HAND = character:FindFirstChild("RightHand")
-- Function to start swinging
local function startSwing()
if isSwinging or humanoid:GetState() == Enum.HumanoidStateType.Dead then return end
if not UPPER_ARM or not HAND then
print("Cannot find R15 arms for IK. Swinging without IK.")
end
-- 1. Raycasting
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {character}
local origin = workspace.CurrentCamera.CFrame.Position
local direction = (mouse.Hit.Position - origin).Unit * MAX_SWING_DISTANCE
local result = workspace:Raycast(origin, direction, raycastParams)
if result and result.Instance then
isSwinging = true
local hitPart = result.Instance
local hitPoint = result.Position
swingPart = hitPart
-- 2. Create attachments
swingAttachment = Instance.new("Attachment")
swingAttachment.Name = "SwingAttachment"
swingAttachment.Position = hitPart.CFrame:PointToObjectSpace(hitPoint)
swingAttachment.Parent = hitPart
local characterAttachment = rootPart:FindFirstChild("RootAttachment")
if not characterAttachment then
characterAttachment = Instance.new("Attachment")
characterAttachment.Name = "RootAttachment"
characterAttachment.Parent = rootPart
end
-- 3. Create BallSocketConstraint for swinging physics
swingConstraint = Instance.new("BallSocketConstraint")
swingConstraint.Attachment0 = swingAttachment
swingConstraint.Attachment1 = characterAttachment
swingConstraint.LimitsEnabled = true
swingConstraint.MaxFrictionTorque = 0 -- Allow free rotation
swingConstraint.Restitution = 0
swingConstraint.TwistLimitsEnabled = false
swingConstraint.Parent = rootPart
-- 4. Create visual web using Beam
webBeam = Instance.new("Beam")
webBeam.Attachment0 = characterAttachment
webBeam.Attachment1 = swingAttachment
webBeam.Width0 = 0.3
webBeam.Width1 = 0.3
webBeam.Color = ColorSequence.new(Color3.new(1, 1, 1))
webBeam.Transparency = NumberSequence.new(0.2)
webBeam.FaceCamera = true
webBeam.Parent = rootPart
-- 5. Apply initial swing boost
local swingDirection = rootPart.CFrame.LookVector
local upwardBoost = Vector3.new(0, 20, 0) -- Add upward component
humanoid:ApplyImpulse((swingDirection * SWING_BOOST) + upwardBoost)
-- 6. Setup IK
if UPPER_ARM and HAND then
handTargetAttachment = Instance.new("Attachment")
handTargetAttachment.Name = "IK_WebTarget"
handTargetAttachment.Parent = workspace.Terrain
ikControl = Instance.new("IKControl")
ikControl.Type = Enum.IKControlType.Reach
ikControl.ChainRoot = UPPER_ARM
ikControl.EndEffector = HAND
ikControl.Target = handTargetAttachment
ikControl.Parent = humanoid
end
end
end
-- Function to stop swinging
local function stopSwing()
if not isSwinging then return end
isSwinging = false
isClimbing = false
-- Clean up
if swingConstraint then
swingConstraint:Destroy()
swingConstraint = nil
end
if swingAttachment then
swingAttachment:Destroy()
swingAttachment = nil
end
if webBeam then
webBeam:Destroy()
webBeam = nil
end
if ikControl then
ikControl:Destroy()
ikControl = nil
end
if handTargetAttachment then
handTargetAttachment:Destroy()
handTargetAttachment = nil
end
swingPart = nil
-- Jump boost when releasing
local velocity = rootPart.AssemblyLinearVelocity
local forwardBoost = velocity.Unit * 20
local upwardBoost = Vector3.new(0, 30, 0)
humanoid:ApplyImpulse(forwardBoost + upwardBoost)
end
-- === GRABBING MECHANIC ===
local function findGrabbablePart()
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {character}
local origin = workspace.CurrentCamera.CFrame.Position
local direction = (mouse.Hit.Position - origin).Unit * GRAB_DISTANCE
local result = workspace:Raycast(origin, direction, raycastParams)
if result and result.Instance and result.Instance:IsA("BasePart") and not result.Instance.Anchored then
return result.Instance
end
return nil
end
local function startGrabbing()
if not grabbedObject then
grabbedObject = findGrabbablePart()
if grabbedObject then
isPulling = true
end
end
end
local function stopGrabbing()
isPulling = false
grabbedObject = nil
end
-- === HEARTBEAT ===
RunService.Heartbeat:Connect(function(deltaTime)
if isSwinging then
-- 1. Climbing (pull yourself up the web)
if isClimbing and swingAttachment then
local pullDirection = (swingAttachment.WorldPosition - rootPart.Position).Unit
humanoid:ApplyImpulse(pullDirection * CLIMB_SPEED * deltaTime * 50)
end
-- 2. Update IK Hand Position
if handTargetAttachment and swingAttachment then
local attachmentWorldPos = swingAttachment.WorldPosition
local rootPos = rootPart.Position
local webDirection = (attachmentWorldPos - rootPos).Unit
local handGripPosition = rootPos + (webDirection * HAND_OFFSET_DISTANCE)
handTargetAttachment.WorldCFrame = CFrame.lookAt(handGripPosition, attachmentWorldPos)
end
-- 3. Add some swing momentum (optional - makes swinging feel better)
local horizontalVelocity = Vector3.new(rootPart.AssemblyLinearVelocity.X, 0, rootPart.AssemblyLinearVelocity.Z)
if horizontalVelocity.Magnitude > 5 then
humanoid:ApplyImpulse(horizontalVelocity.Unit * 2)
end
end
-- 4. Pull grabbed objects
if isPulling and grabbedObject and grabbedObject.Parent then
local targetPosition = rootPart.Position + rootPart.CFrame.LookVector * 3
local direction = (targetPosition - grabbedObject.Position).Unit
grabbedObject.AssemblyLinearVelocity = direction * PULL_SPEED
end
end)
-- === CONTROLS ===
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.E then
startSwing()
end
if input.KeyCode == Enum.KeyCode.Space then
isClimbing = true
end
if input.KeyCode == Enum.KeyCode.Z then
startGrabbing()
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
stopSwing()
end
if input.KeyCode == Enum.KeyCode.Space then
isClimbing = false
end
if input.KeyCode == Enum.KeyCode.Z then
stopGrabbing()
end
end)
humanoid.Died:Connect(function()
stopSwing()
stopGrabbing()
end)