Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Anyway to speed up CFrame animation?

Asked by 6 years ago

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?

1local Door = script.Parent:WaitForChild("Door")
2local Hinge = script.Parent:WaitForChild("Hinge")
3 
4local hingePos = Hinge.Position
5 
6for 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()
9end
0
You shouldn't store the position as a variable, as it will not update if it changes. For line 7, I'd replace "hingePos" with Hinge.Position. Off-topic, but I sent a discord request. User#19524 175 — 6y
0
replace wait() with game:GetService("RunService").Heartbeat:Wait() so it can go faster the8bitdude11 358 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

I recommend a tween because they're easy to use

1local goals = {
2    CFrame = CFrame.new(CFRAMEHERE) -- the ending CFrame position
3}
4 
5local Speed = 2 -- in seconds
6 
7local tween = game:GetService("TweenService"):Create(DoorHinge, TweenInfo.new(Speed), goals)
8 
9tween:Play()

more info at https://wiki.roblox.com/index.php?title=API:Class/TweenService

Ad
Log in to vote
1
Answered by 6 years ago

Put your door inside of a model, then place this script into the model!

01function open()
02local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(-90),0)
03for i = 0,1,.1 do
04    local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i)
05    script.Parent:SetPrimaryPartCFrame(cfm)
06                    wait()
07end
08end
09 
10function close()
11local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
12for i = 0,1,.1 do
13    local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i)
14    script.Parent:SetPrimaryPartCFrame(cfm)
15                    wait()
16end
17end

Then use open() to active the open animation, then close() to active the close animation. <3

Answer this question