Code from this article
local door = script.Parent.Door
local hinge = script.Parent.Hinge
local offset = hinge.CFrame:inverse() * door.CFrame;
game:GetService("RunService").Heartbeat:connect(function(dt)
hinge.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(1)*dt*60, 0)
door.CFrame = hinge.CFrame * offset
end)
Regarding the offset, how come it doesn’t have to be redifined everytime the hinge is rotated, for example wouldn’t it make more sense if it would only work if it was inside the heartbeat function as the CFrame of the hinge changes every heartbeat making it so the offset value also has to change?:
local door = script.Parent.Door
local hinge = script.Parent.Hinge
local offset
game:GetService("RunService").Heartbeat:connect(function(dt)
hinge.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(1)*dt*60, 0)
offset = hinge.CFrame:inverse() * door.CFrame;
door.CFrame = hinge.CFrame * offset
end)
I think I have misunderstood the nature of CFrames, can someone explain how this works?