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

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

Asked by 5 years ago

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)

0
What are you using as a door motor? brok4d 77 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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

0
I wanted to tween it. Which is why I used motors ixUltraz 28 — 5y
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 theking48989987 2147 — 5y
0
Motor6D ixUltraz 28 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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))
0
but that rotates it around the center of the object, not around a hinge like a door would theking48989987 2147 — 5y

Answer this question