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
?
1 | local Door = script.Parent:WaitForChild( "Door" ) |
2 | local Hinge = script.Parent:WaitForChild( "Hinge" ) |
3 |
4 | local hingePos = Hinge.Position |
5 |
6 | for i = 0 , - 80 , - 1 do |
7 | Door.CFrame = CFrame.new(hingePos) * CFrame.Angles( 0 , math.rad(i), 0 ) * CFrame.new( 2.6 , 0 , 0 ) |
8 | wait() |
9 | end |
I recommend a tween because they're easy to use
1 | local goals = { |
2 | CFrame = CFrame.new(CFRAMEHERE) -- the ending CFrame position |
3 | } |
4 |
5 | local Speed = 2 -- in seconds |
6 |
7 | local tween = game:GetService( "TweenService" ):Create(DoorHinge, TweenInfo.new(Speed), goals) |
8 |
9 | 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!
01 | function open() |
02 | local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles( 0 ,math.rad(- 90 ), 0 ) |
03 | for i = 0 , 1 ,. 1 do |
04 | local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i) |
05 | script.Parent:SetPrimaryPartCFrame(cfm) |
06 | wait() |
07 | end |
08 | end |
09 |
10 | function close() |
11 | local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles( 0 ,math.rad( 90 ), 0 ) |
12 | for i = 0 , 1 ,. 1 do |
13 | local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i) |
14 | script.Parent:SetPrimaryPartCFrame(cfm) |
15 | wait() |
16 | end |
17 | end |
Then use open() to active the open animation, then close() to active the close animation. <3