Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Anyway to speed up CFrame animation?

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

2 comments

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.

0

replace wait() with game:GetService("RunService").Heartbeat:Wait() so it can go faster

2 answers

✓ Accepted answer

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

2 comments

0

...

This discussion is preserved as it was. New answers, comments, and votes are closed.