While looking for ways to spice up my team’s game, I looked at the wind and thought “why doesn’t this affect ropes?”. I didn’t actually think that, I just thought that would make for a cool story. Anyways.
This is the, mostly basic, code:
Summary
--[[ for an automatic setup, paste this in your command bar:
local folder = Instance.new('Folder'); folder.Name = 'WindAffectedRopes'; folder.Parent = workspace; for _, v in ipairs(workspace:GetDescendants()) do if v:IsA('RopeConstraint') then v.Parent = folder end end
]]
-- services
local TweenService = game:GetService('TweenService')
local Players = game:GetService('Players')
-- instances
local Camera = workspace.CurrentCamera
local SimSettings = {
-- the folder where the script looks for ropes (just drag your ropeconstraints in there, it won't break anything)
Folder = workspace:WaitForChild('WindAffectedRopes'),
-- the tween settings for the ropes
TweeningInfo = TweenInfo.new(1.2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, -1, true),
-- i recommend leaving this value as is
Amount = 0.1,
-- the distance between each rope and the player when ropes stop moving
MaxDist = 20
}
-- script-controlled variables
local ropes = {}
local tweens = {}
for _, rope in ipairs(SimSettings.Folder:GetChildren()) do
if rope:IsA('RopeConstraint') then
local oldLength = rope.Length
local tween = TweenService:Create(rope, SimSettings.TweeningInfo, {Length = oldLength-SimSettings.Amount})
tween:Play()
table.insert(ropes, rope)
table.insert(tweens, tween)
end
end
while task.wait(1) do
for _, rope in ipairs(ropes) do
local dist = (rope.Attachment0.WorldPosition - Camera.CFrame.Position).Magnitude
if dist > SimSettings.MaxDist then
tweens[_]:Pause()
else
tweens[_]:Play()
end
end
end
Basically, it just tweens your rope’s length by SimSettings.Amount
less, to give the impression that it’s swaying around in the wind, since we can’t actually rotate ropes.
Unless you’re a maniac and want to perform this on the server, make a LocalScript in
, then paste this code in there.
Once you’re done, this is optional, but you can also use the command bar with the following code to automatically set things up:
Summary
local folder = Instance.new('Folder'); folder.Name = 'WindAffectedRopes'
folder.Parent = workspace
for _, v in ipairs(workspace:GetDescendants()) do
if v:IsA('RopeConstraint') then
v.Parent = folder
end
end
Tinker with the settings to see what you like. This is what the default looks like, the rope’s length is 20:
This is too good not to make public. Enjoy your slightly more sentient ropes!
Boatbomber's wind module, if you want those trail effects too
Wind Shake: High performance wind effect for leaves and foliage