Erratic Behaviour in 24 segment rope

Hello,
I’m trying to recreate the whiplash from iron man 2
Here I am using a neon cylinder with 24 bones
And a seperate 24 parts that are linked up together by rope constraints
You may think all is well, but it is prone to erratic behaviour:
The rope segments properties:
image
The script used to automate the creation of the rope segments:

for i=1,24 do
	local par = Instance.new("Part",workspace)
	par.Position = Vector3.new(0,.5*i,0)
	par.Size = Vector3.new(.1,.4,.1)
	par.Name = "gar "..i
	local at0 = Instance.new("Attachment",par)
	local at1 = Instance.new("Attachment",par)
	at0.Position = Vector3.new(0,-.2,0)
	at0.Name = "at0"
	at1.Position = Vector3.new(0,.2,0)
	at1.Name = "at1"
	if i>1 then
		local rope = Instance.new("RopeConstraint",par)
		rope.Restitution = .2
		rope.Length = .1
		rope.Attachment0 = at0
		rope.Attachment1 = workspace["gar "..i-1].at1
	end
end

The script that aligns the cylinder neon with the rope segments:

local mou = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
local gar = false
script.Parent.Equipped:Connect(function()
	gar = true
	repeat
		wait()
		script.Parent.Circle.Bone.WorldPosition = tool["gar 1"].Position
		script.Parent.Circle.Bone.WorldOrientation = tool["gar 1"].Orientation

		for i = 1,9 do
			script.Parent.Circle["Bone.00"..i].WorldPosition = tool["gar "..i+1].Position
			script.Parent.Circle["Bone.00"..i].WorldOrientation = tool["gar "..i+1].Orientation
		end
		for i = 10,23 do
			script.Parent.Circle["Bone.0"..i].WorldPosition = tool["gar "..i+1].Position
			script.Parent.Circle["Bone.0"..i].WorldOrientation = tool["gar "..i+1].Orientation
		end
	until gar == false
end)
script.Parent.Unequipped:Connect(function()
	gar = false
end)

The cylinder is welded to the handle
Diagram:


Video of erratic behaviour:

My need:
How can I fix this?
Are this other ways to improve this (other than the erratic behaviour)

- Br, iSyriux

I think the problem is because the rope is CanCollide and Massless so the player can fling and be flung by the parts.

Since the parts are unanchored, you can’t set the rope to non-CanCollide without the rope falling through the floor, so you should use PhysicsServices to disable collisions between players and the rope with Collision Filtering

1 Like

Hello,
Thank you for replying. I have taken your advice and I am not getting flung out of nowhere anymore. However, I still get pushed midair one direction when I jump while holding out the whip. I don’t know why.

Hello,
R

Okay, so now in your recent video (and something I overlooked in the first video), the player is being dragged by the rope on equip, probably to where the rope was previously unequipped. And then when you get flung the rope is somehow pushing you.

This seems to be a pretty difficult physics problem that won’t be perfect without some massive overhaul that I don’t really know enough about to help you with, but I have one last idea on how to make it work better.

In your Equipped function, you essentially use a while wait() do loop, which is something that I would strongly advise against in anything other than a prototype. You can use RunService to avoid these types of loops. I usually use Heartbeat because its more consistent and I’m more comfortable using, but it might be beneficial for you to use RenderStepped or Stepped instead as they work slightly differently.

Here’s how I think your code could be better structured:

local RunService = game:GetService("RunService") -- get RunService
local connection -- hold the RunService connection

script.Parent.Equipped:Connect(function()
    local function drawRope()
        -- put your code for positioning the rope here
    end
    drawRope() -- draw the rope instantly so you don't need to wait for next frame. Might help with the pulling
    connection = RunService.Heartbeat:Connect(function(drawRope) -- every frame, draw the rope
end)

script.Parent.Unequipped:Connect(function()
    if connection then
        connection:Disconnect()
    end
end)

Did you ever figure out why the rope pushes you when you jump? I still can’t figure that out with my single segment rope.