Tweening a constant spin

What I want is to constantly spin a part using TweenService. What happens with the code below is that when it finishes its 120 turn, it resets instead on continuing to rotate from where it is currently at.

I search the forum and found threads, but none actually worked for me.


        local tweenInfo = TweenInfo.new(
            2, 
            Enum.EasingStyle.Linear, -- EasingStyle
	        Enum.EasingDirection.In, -- EasingDirection
	        -1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	        false, -- Reverses (tween will reverse once reaching it's goal)
	        0 -- DelayTime
        )

        local spinTween = TweenService:Create(newBlackHole, tweenInfo, {CFrame = CFrame.new(newBlackHole.Position) * CFrame.fromEulerAnglesXYZ(0, math.rad(120), 0)})
        spinTween:Play()

Why are you doing it in 120 degree increments? Why not just tween it 360 degrees?

1 Like

if you tween to 360 degrees it doesnt move because thats the same orientation its already at

Honestly this issue comes up over and over on the forums and I have yet to see a decent way to constantly tween rotation.

I did it another way once, but that involved creating a old weld(deprecated weld) via script because they cannot be created in studio, then tweening the C1 property of the wel,d but that required extra parts because the part in question cannot be anchored to tween the weld!

we need a good solution to this

Why do you even need to tween the spin? Can’t you just add a value to the “orientation” of the part?

Tween is used to provide smooth motion without binding anything to RenderStepped, if thats what your recommending.

This is exactly the sort of thing TweenService is for, so thats why I am trying to find someone who has done it. I use TweenService for all sorts of part animation tasks, but continuously rotating a part has proven very troublesome.

I dont want to use BodyMovers or Motor6d or bind anything to RenderStepped

You could attach a motor6d, animate with looping turned on, and then play it using a script, right? Or just use tween service for every 90*, 180*, 270* turn. I don’t really understand using tweenservice for this.

spinTween = TweenService:Create(newBlackHole, tweenInfo, {CFrame = CFrame.new(newBlackHole.Position) * CFrame.fromEulerAnglesXYZ(0, math.rad(newBlackHole.fromEulerAnglesXYZ.Y + 120), 0)})
spinTween:Play()

well thanks anyway, but i said i didnt want to create a motor6d already. Creating animations and motor6d is really quite a lot of work and overhead for something so simple. Animations need to be uploaded to Roblox then downloaded to the game at runtime. This is really not ideal.

using TweenService is common practice to move and rotate parts. So the subject of the thread is what I am after, using Tweens to constantly spin a part.

just add 120 to the spin tween’s Y value in math.rad.

2 Likes

that line of code you posted does not work, fromEulerAngles is not a valid member of that part, not sure how to make it work

this is an utter mess, i think it might be literally impossible or at least ridiculously hard to spin a part using tweenservice looping.

PROVE ME WRONG! :stuck_out_tongue:

local numberValue = Instance.new("NumberValue")
numberValue.Changed:Connect(function(value)
    newBlackHole.CFrame = CFrame.Angles(0, math.rad(value), 0) + newBlackHole.Position
end)

local valueTween = TweenService:Create(numberValue, tweenInfo, { Value = 360 })
valueTween.Completed:Connect(function()
    numberValue.Value = 0

    wait()

    valueTween:Play()
end)

valueTween:Play()

Make sure that ‘reverses’ in the TweenInfo is false and ‘repeatCount’ is 0 and ‘EasingStyle’ is ‘Linear’.


Alternatively you might be able to set the Y rotation goal of the tween to math.huge, which will keep it running for a looooong time. Roblox usually maps the set value to 0-360 (or -180-180, not sure) internally anyways. Not sure if it works with tweening though.

Couldn’t you just do

local tweenService = game:GetService('TweenService')
local part = workspace.Part
local tweenInfo = TweenInfo.new(
    2, 
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.In,
    0,
    false,
    0
)
while true do
    local tween = TweenService:Create(part, tweenInfo, {CFrame = part.CFrame * CFrame.Angles(0,math.rad(90), 0)})
    tween:Play()
    tween.Completed:Wait()
end

The reason yours isn’t working is because it’s just tweening to the same orientation over and over again which is why it looks like nothing is happening (result of setting RepeatCount to -1).

2 Likes

Alternatively you can rotate it by 120 degrees then once the tween completes add a Tween.Completed event. But it seems you are editing it’s Orientation properties so maybe just edit it’s orientation like this?

local tweenInfo = TweenInfo.new(
	2, 
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.In, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

local spinTween = TweenService:Create(newBlackHole, tweenInfo, {Orientation = newBlackHole.Orientation + Vector3.new(0, 360, 0)})
spinTween:Play()

It seems to work just fine.

2 Likes