Tweening taking shortest path

Im trying to make a wheel spin 4 times (1440deg)

However with tweenservice when i enter the cframe rotation

StartCFrame * CFrame.Angles(math.rad(1440),0,0)

It takes the shortest path to this route, which is just 45 degrees to the left.
I want it to make the full 4 rotations how can i do so?

^ To keep in mine i want to use easingstyle sine, If i split it up into like 4 360’s the sine does work aswell

1 Like

try tuning the tween direction in the TweenInfo.new()

It still ends up taking the shortest path no matter what

are you changing the easing direction?

Ill try again which should i set it too? Out?

1 Like

local StartCF = script.Parent.CFrame

local TS = game:GetService("TweenService")

local T = TS:Create(script.Parent, TweenInfo.new(5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
	CFrame = StartCF * CFrame.Angles(math.rad(1340),0,0)
})
T:Play()

same thing it just takes the shortest path.

Try adding the rotation specifically not combining 2 CFrames

local TweenService = game:GetService("TweenService")

local part = script.Parent
local rotationGoal = 360 * 4 -- Rotate 4 times (360 degrees per rotation)

local tweenInfo = TweenInfo.new(
	-- Duration of the tween in seconds
	10, 
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.InOut,
	-- Number of times to repeat
	0, -- -1 means infinite
	false,
	0
)

local rotationTween = TweenService:Create(
	part, 
	tweenInfo, 
	{Rotation = part.Rotation + Vector3.new(0, 0, rotationGoal)}
)

-- Start the tween
rotationTween:Play()

-- Stop the tween after it completes 4 rotations
rotationTween.Completed:Connect(function()
	rotationTween:Cancel()
end)

banner

The issue with this is i have parts welded to it, and using rotation doesnt carry the parts

This is because of the way CFrame math works. When you do StartCFrame * CFrame.Angles(math.rad(1440),0,0), it isn’t stored as “a 1440 degree rotation.” Yes, you’re rotating it by 1440 degrees, but the final CFrame will have a rotation between -180 and 180 on that particular axis, and that’s what you’re passing to the tween.

To achieve something like this, you’ll want to use a custom tween implementation. I recommend Tween.lua by Sleitnick, but there are plenty out there to use.

Here’s a code example of how you would use it:

local tween = Tween.new(TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true, 0), function(n)
	local cframe = StartCFrame * CFrame.Angles(math.rad(1440 * n), 0, 0)
end)

Because it works using an alpha value and you’re computing the CFrame again each step, it will gradually approach your desired 1440 degree rotation.

This works great, however it doesnt even land at the desired rotation,
The rotation is the exact same everytime.
Unsure why my code is


	local tween = Tweener.new(TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), function(n)
		local cframe = CenterPart.CFrame * CFrame.Angles(math.rad(endRotation * n), 0, 0)
		print(n)
		--print(cframe)
		CenterPart.CFrame = cframe
	end)
	
	tween:Play()
	tween.Completed:Wait()

Video:
https://streamable.com/xt9n8k

The following snippet:

CenterPart.CFrame * CFrame.Angles(math.rad(endRotation * n), 0, 0)

Should be changed to use the start CFrame instead of the current CFrame.

1 Like

it works now!
Thank you man I appreciate it no clue how we both missed that lol.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.