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

TweenService Easing Direction Problem?

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)

2 comments

0

CFrame includes both position and rotation, when you don't include rotation values it sets it to 0

0

How would I include rotation values?

1 answer

✓ Accepted answer

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.

1 comment

0

Sorry if I kinda bumped this question.

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