使用绳索约束连接网格

我正在尝试使用ROBLOX的新绳索约束和一组零件做出一种“布料模拟”。

目前,我已经制作了一个10x10的一组.4x.4x.4块,并且现在我想用绳索约束将每个块连接起来。

我根据它们的行和列用它们的名字和字符串操作来命名网格中的每个部分(例如:网格中的第一个部分为1 1,最后一个为10 10)

然后我在每个部件中插入4个连接点和4个绳索约束。 以下是代码(ab代表上面,be代表下面,等等):

for i2 = 1,#gParts do
  local ab = tostringtonumber(gParts[i2].Name:match(“^(%S +)”))-5)..'   '..tostringtonumberstring.sub(gParts[i2].Name,-1))-1local be = tostringtonumber(gParts[i2].Name:match(“^(%S +)”))+5)..'   '..tostringtonumberstring.sub(gParts[i2].Name,-1))+1local le = tostringtonumber(gParts[i2].Name:match(“^(%S +)”))-1)..'   '..tostringtonumberstring.sub(gParts[i2].Name,-1)))
  local ri = tostringtonumber(gParts[i2].Name:match(“^(%S +)”))+1)..'   '..tostringtonumberstring.sub(gParts[i2].Name,-1)))
  for i3 = 14 do
    local atchm = Instance.new(“Attachment”,gParts[i2])
    local ropeconst = Instance.new(“RopeConstraint”,gParts[i2])
  end
end

绳索约束有两个我需要使用的主要属性:连接点1和连接点2。

点赞
用户5565844
用户5565844

我从来没有真正尝试过新的约束,但我相信这应该可行。

请记住,约束是Roblox中的一个新实例,它们很可能仍然是实验性的。

X = 10;
Y = 10;
spread = 4;
--Spread是约束的长度。你可能需要增加这个长度,特别是如果它很僵硬。

function createAttachments()
    --这是在假定gParts是填充了Part实例的表的情况下进行的
    for i,v in pairs(gParts) do
        local atch = Instance.new("Attachment",v);
    end;
end;

function connectConstraints(part,x,y)
    if x ~= X then
        connectRight = x+1.." "..y;
    end;
    if y ~= Y then
        connectDown = x.." "..y+1;
    end;
    if connectRight ~= nil then
        local ropeconst = Instance.new("RopeConstraint",part);
        ropeconst.Length = spread;
        ropeconst.Attachment0 = part.Attachment;
        ropeconst.Attachment1 = connectRight.Attachment;
    end;
    if connectLeft ~= nil then
        local ropeconst = Instance.new("RopeConstraint",part);
        ropeconst.Length = spread;
        ropeconst.Attachment0 = part.Attachment;
        ropeconst.Attachment1 = connectLeft.Attachment;
    end;
end;

createAttachments();
connectConstraints();

如果这对你不起作用,请告诉我。如果需要,我可以从网站本身联系你。

2016-08-25 14:42:24