【问题标题】:C-Frame Sliding Door in Roblox Studio ScriptRoblox Studio 脚本中的 C 型框架推拉门
【发布时间】:2015-12-22 20:29:49
【问题描述】:

以目前脚本的复杂性和我的能力,我在研究如何在流行的 MMO“Roblox”中创建一个滑动门时遇到了死胡同。 我已经自动和手动分析了脚本,没有发现任何错误。 如下:

local Part = workspace.Part
local newPos = Part.Position + Vector3.new(-61.866, 8.551, -97.181)
local Time = 5
local Increment = 0.5 
local Debounce = false

local Diff = newPos - Part.Position
local Mag = Diff.magnitude
local Direction = CFrame.new(Part.Position, newPos).lookVector

function MovePart()
if Debounce then return end
    Debounce = true
    for n = 0, Mag, Increment do
        Part.CFrame = Part.CFrame + (Direction * Increment)
        wait( (Time/Mag) * Increment )
    end
    Debounce = false
end

workspace.Button.ClickDetector.MouseClick:connect(MovePart)

当我插入一个带有Clickdetector 的按钮并尝试单击该按钮时,没有显示任何结果 - 甚至没有错误!我被困住了,需要帮助。将不胜感激。

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    嗯,适合我。
    是否已经在 (-61.866, 8.551, -97.181)?
    是否还有另一个“零件”或“按钮”?
    它不是锚定的吗?

    替代解决方案:
    将按钮、部件和以下脚本放在一个模型中。

    local Part = script.Parent.Part
    local Button = script.Parent.Button
    Part.Anchored = true
    local Direction = Part.CFrame.lookVector
    local Mag = Part.Size.Z
    
    local Time = 5
    local Increment = 0.5 -- Smaller will make smoother 'movement'
    local Debounce = false
    
    function MovePart()
    if Debounce then return end
        Debounce = true
        for n = 0, Mag, Increment do
            Part.CFrame = Part.CFrame + (Direction * Increment)
            wait(Time/(Mag * Increment))
        end
        for n = 0, Mag, Increment do
            Part.CFrame = Part.CFrame + (Direction * -Increment) -- so that it moves back
            wait(Time/(Mag * Increment))
        end
        Debounce = false
    end
    
    clickD = Button.ClickDetector or Instance.new("ClickDetector",Button)
    clickD.MouseClick:connect(MovePart)
    

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      您所要做的就是在工作区中放置一个部件,将其重命名为“Button”,然后在该部件中插入一个 clickDetector。

      【讨论】:

        猜你喜欢
        • 2019-05-20
        • 2023-01-26
        • 2021-12-06
        • 2022-11-02
        • 2019-10-15
        • 2018-11-26
        • 2021-04-02
        • 2018-12-01
        • 2020-12-21
        相关资源
        最近更新 更多