2016-04-20 34 views
0

我一直在試圖製作一款遊戲,你在一個正方形中,當你走到兩邊時,部件會出現並阻擋你。根據距離改變Y軸上的位置

我已經得到了遠到它的正常工作,除了幾個問題點:

部分去的時候沒有提出下面的廣場,我想,當他們沒有提出

它們可見

當您跳起時,零件會下降,使其易於逃生。

部件上升得太早

這是處理牆壁定位的代碼。

for _, v in pairs(model:GetChildren()) do 
    if string.sub(v.Name,1,4) == "Wall" then 
     local walls = {} 
     walls[v] = {v.CFrame,Vector3.new(1, 1, 1)} 
     game:GetService("RunService").RenderStepped:connect(function() 
      if(workspace[game.Players.LocalPlayer.Name]:FindFirstChild("HumanoidRootPart")) then 
       local mag = (v.Position - workspace[game.Players.LocalPlayer.Name]:FindFirstChild("HumanoidRootPart").Position).magnitude 
       sizeFactor = math.floor(mag) 
       v.CFrame = walls[v][1]*CFrame.new(0,-sizeFactor+(walls[v][1].Y*1.8),0) 

      end 
     end)  
    end 
end 

你可以看到我的比賽在這裏:https://www.roblox.com/games/400391033/Marble-walls

回答

0

見註釋代碼。

   for _, v in pairs(model:GetChildren()) do 
       if string.sub(v.Name,1,4) == "Wall" then 
        local walls = {} 
        walls[v] = {v.CFrame,Vector3.new(1, 1, 1)} 
        game:GetService("RunService").RenderStepped:connect(function() 
         if(workspace[game.Players.LocalPlayer.Name]:FindFirstChild("HumanoidRootPart")) then 
          local mag = (v.Position - workspace[game.Players.LocalPlayer.Name]:FindFirstChild("HumanoidRootPart").Position).magnitude 
          if (mag <= 2) then --[[ 
            Currently your issue is that you never actually do ANYTHING regarding magnitude 
            you essentially change the y-Axis as soon as the player spawns.. hence why it does it too early 
            kappa 
           ]] 
           sizeFactor = math.floor(mag) 
           v.CFrame = walls[v][1]*CFrame.new(0,-sizeFactor+(walls[v][1].Y*1.8),0) 
          end; 
         end 
        end)  
       end 
      end