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

How do I fix this tweening Issue, The door is rotating?

https://gyazo.com/5c068ec1e83e960b23290def0c5b761c Can someone help me?

Heres the code

local Open1 = {CFrame = CFrame.new(-96.788, -5.164, 13.217)}
local Closed1 = {CFrame = CFrame.new(-94.578, -5.164, 13.217)}
local Open2 = {CFrame = CFrame.new(-88.528, -5.034, 13.217)}
local Closed2 = {CFrame = CFrame.new(-91.378, -5.034, 13.217)}
local tweenService = game:GetService("TweenService")
local Door1 = script.Parent.Door.Motor
local Door2 = script.Parent.Door2.Motor


local tweeningInfo = TweenInfo.new(
	
	0.5,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.In,
	0,
	false,
	0
	
)

local TweenOpen1 = tweenService:Create(Door1, tweeningInfo, Open1)
local TweenClosed1 = tweenService:Create(Door1, tweeningInfo, Closed1)
local TweenOpen2 = tweenService:Create(Door2, tweeningInfo, Open2)
local TweenClosed2 = tweenService:Create(Door2, tweeningInfo, Closed2)

script.Parent.Close2.ClickDetector.MouseClick:Connect(function()
	TweenClosed1:Play()
	TweenClosed2:Play()
end)

script.Parent.Open.ClickDetector.MouseClick:Connect(function()
	TweenOpen1:Play()
	TweenOpen2:Play()
end)

1 comment

0

What are you using as a door motor?

2 answers

✓ Accepted answer

I feel that the tutorial by DutchDeveloper explained it pretty well in this video:

https://www.youtube.com/watch?v=Zqa10ImXCRs&t=12s

Basically, it first involves making a model with the hinge of the door as the primary part, and then using the SetPrimaryPartCFrame() function of models to rotate the model w/ CFrame.Angles()

local door = script.Parent --model
local cfm = door.PrimaryPart.CFrame
for i = 0,1,0.05 do
	local goal = cfm* CFrame.Angles(0,-math.pi/2,0)
	local cf = door.PrimaryPart.CFrame:Lerp(goal,i)
	door:SetPrimaryPartCFrame(cf)
	wait()
end

This to the best of my knowledge is the only one way of rotating an object around a hinge/ center.

the code used above is using a function of CFrame named CFrame:Lerp() (linear interpolation). The code first makes a numeric for loop and sets a goal for the lerp function, which in this case is

door.PrimaryPart.CFrame* CFrame.Angles(0,-math.pi/2,0) or basically the door's CFrame rotated -pi/2 radians (-90 degrees) on the y axis..

Now note that the lowest value of the numeric for loop and the highest value are 0 and 1 respectively. Thus being useful for CFrame:Lerp() as the alpha value of the function.

To explain a bit about lerping in case you are new to it or confused about it, lerping in essence is this

function lerp(a, b, c)
	return a + (b - a) * c;
end

a being the starting value, b being the end value, c being the alpha between 0 and 1.

so you then lerp from the stating CFrame to the end CFrame by the alpha of i. then using the :SetPrimaryPartCFrame function to set the actual CFrame of the model to the lerped CFrame

If there is anything wrong, just leave a comment

3 comments

0

I wanted to tween it. Which is why I used motors

0

please explain what type of motor can be tweened? the only type of motor i can find in the surface type of a part

0

Motor6D

You should put a rotation, you can't just use the position use this

Cframe.new(X,Y,Z)*CFrame.FromOrienation(math.rad(X),math.rad(Y),math.rad(Z))

1 comment

0

but that rotates it around the center of the object, not around a hinge like a door would

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