我正在尝试在 Roblox Studio 中制作一个动画打开/关闭门。该脚本有效,但它旋转的是铰链而不是门。请告诉我我做错了什么,我该如何解决这个问题?
local tween = game:GetService("TweenService")
local Center = script.Parent.Center
local Door = "Closed"
local CF = Instance.new("CFrameValue")
CF.Value = Center.CFrame
CF.Changed:Connect(function()
Center.CFrame = CF.Value
end)
script.Parent.Door.ClickDetector.MouseClick:Connect(function()
if Door == "closed" then
tween:Create(CF, TweenInfo.new(1), {Value = Center .CFrame * CFrame.Angles(math.rad(0),math.rad(90),math.rad(0))}):play()
Door = "open"
else
tween:Create(CF, TweenInfo.new(1), {Value = Center .CFrame * CFrame.Angles(math.rad(0),math.rad(-90),math.rad(0))}):play()
Door = "closed"
end
end)
从你的脚本设置方式来看,铰链是你的
script.Parent
,门是你的script.Parent.Door
,所以在你定义Center
的行上你应该写:
local Center = script.Parent.Door
这样您就不会参考铰链,而是参考门,并相应地调整 CFrame 旋转值。