Basically, I am making a door open with this animation which rotates on a hinge I have created. Is there any way I can make this faster or even possibly use TweenService
?
local Door = script.Parent:WaitForChild("Door") local Hinge = script.Parent:WaitForChild("Hinge") local hingePos = Hinge.Position for i = 0, -80, -1 do Door.CFrame = CFrame.new(hingePos) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(2.6, 0 ,0) wait() end
I recommend a tween because they're easy to use
local goals = { CFrame = CFrame.new(CFRAMEHERE) -- the ending CFrame position } local Speed = 2 -- in seconds local tween = game:GetService("TweenService"):Create(DoorHinge, TweenInfo.new(Speed), goals) tween:Play()
more info at https://wiki.roblox.com/index.php?title=API:Class/TweenService
Put your door inside of a model, then place this script into the model!
function open() local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(-90),0) for i = 0,1,.1 do local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i) script.Parent:SetPrimaryPartCFrame(cfm) wait() end end function close() local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0) for i = 0,1,.1 do local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i) script.Parent:SetPrimaryPartCFrame(cfm) wait() end end
Then use open() to active the open animation, then close() to active the close animation. <3