Why do my doors behave unexpectedly in ROBLOX Studio using TweenService()?

时间:2019-04-17 00:55:46

标签: lua roblox

So I'm building a Maze Runner game for ROBLOX and I've gotten to scripting the doors, so I utilized ROBLOX's built in "TweenService()" to do it. In theory, the doors should slide into the walls like in the Maze Runner. But This keeps happening and i don't know why! They rotate into the gap rather than sliding. I would show an image but i can't. | = walls V = doors. What should happen |><| what happened |^^|

My Code:

        TweenService = game:GetService("TweenService")
    Door = script.Parent.Door2
    Door1 = Door:WaitForChild("Door1")
    Door2 = Door:WaitForChild("Door2")
    local TweenInformationIn = TweenInfo.new(

        6,
        Enum.EasingStyle.Sine,
        Enum.EasingDirection.In,
        0,
        false,
        0
    )

    local Door1Close = {CFrame = CFrame.new(1226.993, 131.187, -769.185)}
    local Door2Close = {CFrame = CFrame.new(1226.993, 131.187, -814.271)}
    local Door1Open = {CFrame = CFrame.new(1226.993, 131.187, -749.831)}
    local Door2Open = {CFrame = CFrame.new(1226.993, 131.187, -834.331)}
    local Tween1Open = TweenService:Create(Door1, TweenInformationIn, Door1Open)
    local Tween2Open =  TweenService:Create(Door2, TweenInformationIn,Door2Open)
    local TweenClose =  TweenService:Create(Door1, TweenInformationIn, Door1Close)
    local Tween2Close =  TweenService:Create(Door2,TweenInformationIn,Door2Close)

    Tween1Open:Play()
    Tween2Open:Play()

1 个答案:

答案 0 :(得分:0)

您的补间代码看起来不错。

可能只是您定义的CFrame缺少旋转信息。 在您的示例中,您制作的补间尝试将1号门移至Position (1226.993, 131.187, -769.185)Orientation (0, 0, 0)

您需要检查门的Orientation属性,并确保Orientation保留在最终的CFrame中。您可以通过将旋转乘以另一个CFrame来将该旋转应用于该位置。

两个简单的例子是:

-- create a door that swings close
local Door1OpenPos  = CFrame.new(0, 5, 10) * CFrame.fromEulerAnglesXYZ(0, 90, 0)
local Door1ClosePos = CFrame.new(0, 5, 15) * CFrame.fromEulerAnglesXYZ(0,  0, 0)

-- create a door that slides close
local Door2OpenPos  = CFrame.new(20, 5, 0) * CFrame.fromEulerAnglesXYZ(0, 90, 0)
local Door2ClosePos = CFrame.new(30, 5, 0) * CFrame.fromEulerAnglesXYZ(0, 90, 0)

您的滑动门需要确保补间的开始和结束方向相同。

希望这会有所帮助。