This is what I want but instead of it opening open I want it to open down
I tried cframe.angles but that seems to rotate a part from the center
This is what I want but instead of it opening open I want it to open down
I tried cframe.angles but that seems to rotate a part from the center
Depending on where the trapdoor is you have to change the hinge position.
Either the openAngle
OR the hingePosition
is negative when comparing left to right door. Ex. This was the right door, and left door had openAngle = -90
and hingePosition = trapdoorPart.Position + Vector3.new(0, 0, trapdoorPart.Size.Z/2)
local trapdoorPart = script.Parent
local child_variable = trapdoorPart:FindFirstChild("trapdoorPart") and trapdoorPart.trapdoorPart or trapdoorPart
local isOpen = false
local openAngle = 90 --adjust if up or down depending on the side (90 / -90)
local TweenService = game:GetService("TweenService")
local function toggleTrapdoor()
local hingePosition = trapdoorPart.Position + Vector3.new(0, 0, -trapdoorPart.Size.Z/2) -- adjust for hindge position [(-)trapdoorPart.Size.X/2, (-)trapdoorPart.Size.Y/2, (-)trapdoorPart.Size.Z/2]
local targetCFrame
if isOpen then
targetCFrame = CFrame.new(hingePosition) * CFrame.Angles(math.rad(-openAngle), 0, 0) * CFrame.new(-hingePosition) * trapdoorPart.CFrame
isOpen = false
else
targetCFrame = CFrame.new(hingePosition) * CFrame.Angles(math.rad(openAngle), 0, 0) * CFrame.new(-hingePosition) * trapdoorPart.CFrame
isOpen = true
end
local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0) --edit first parameter for Duration (Seconds)
local tween = TweenService:Create(trapdoorPart, tweenInfo, {CFrame = targetCFrame})
tween:Play()
end
toggleTrapdoor()
Use PivotTo function on a model ;d