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?

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
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

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

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!

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

Answer this question