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

TweenService Easing Direction Problem?

Asked by 6 years ago

I am creating a gate that should tween down and upon command. It does but it rotates weird and then does not go where I want it to. After it is open whenever it goes up it should be at the same 90° angle - somewhat a 90° angle.- and it should go back to position but it fails to do so.

Rotation Of Gate: -24.09, 0, 0

Script:

local Gate = workspace:WaitForChild("Gate")
local TweenService = game:GetService("TweenService")
local Activated = false
local Tween1Information = TweenInfo.new(
    1,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.InOut
)
local Tween2Information = TweenInfo.new(
    1,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.InOut
)
local Tween1 = {
    CFrame = CFrame.new(31.749, -26.276, 16.473),
}
local Tween2 = {
    CFrame = CFrame.new(31.749, 25.761, -6.788),
}

local Open = TweenService:Create(Gate,Tween1Information,Tween1)
local Close = TweenService:Create(Gate,Tween1Information,Tween2)

script.Parent.MouseClick:Connect(function()
    if Activated == false then
        Activated = true
        Open:Play()
    elseif Activated == true then
        Activated = false
        Close:Play()
    end
end)
0
CFrame includes both position and rotation, when you don't include rotation values it sets it to 0 User#22604 1 — 6y
0
How would I include rotation values? namespace25 594 — 6y

1 answer

Log in to vote
1
Answered by
Y_VRN 246 Moderation Voter
6 years ago
Edited 6 years ago

You're probably missing "* CFrame.Angles()" in your code, which is after both CFrames in both TweenInfos. Try this


local Gate = workspace:WaitForChild("Gate") local TweenService = game:GetService("TweenService") local Activated = false local Tween1Information = TweenInfo.new( 1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut ) local Tween2Information = TweenInfo.new( 1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut ) local Tween1 = { CFrame = CFrame.new(31.749, -26.276, 16.473)* CFrame.Angles(math.rad(90),0,0) -- This is what is missing. } local Tween2 = { CFrame = CFrame.new(31.749, 25.761, -6.788)* CFrame.Angles(math.rad(0),0,0) -- This is what is missing. } local Open = TweenService:Create(Gate,Tween1Information,Tween1) local Close = TweenService:Create(Gate,Tween1Information,Tween2) script.Parent.MouseClick:Connect(function() if Activated == false then Activated = true Open:Play() elseif Activated == true then Activated = false Close:Play() end end)

Note 1: If you add CFrame.Angles() without changing the X, Y, and Z values to radians (assuming you're using degress (like 90)), put math.rad(DEGREES) first, and change DEGREES to your liking. math.Angles() reads degress as radians (Without math.rad: 90 degrees = CFrame.Angles reads value as rads = 90 rads = 5156.62 degrees (I depend on Google Calculator)). More about Radians at https://en.wikipedia.org/wiki/Radian

Note 2: I used X in CFrame.Angles(X,Y,Z) because I don't know how your gate is supposed to look like. I used a simple brick as a gate. If it is not the right rotation, transfer the math.rad(90) to Y or Z and/or make the value negative to achieve the right rotation.

Hope this works for you.

0
Sorry if I kinda bumped this question. Y_VRN 246 — 6y
Ad

Answer this question