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

How could you make an image rotate back and forth smoothly?

Asked by 6 years ago

I would like a way to rotate something back and forth very efficiently and smooth such as: https://gyazo.com/ce2763e854e1ab7ce923885591125d31

I can't seem to figure out how to do this (I'm sure I am over thinking this).

0
you could use for loops (e.g, for i = 1,30 do) and change the rotation property (e.g gui.rotation = gui.rotation + 1) abnotaddable 920 — 6y
0
Look into http://wiki.roblox.com/index.php?title=API:Class/TweenService/Create. This should allow you to tween almost any property. XAXA 1569 — 6y
0
Thats not tweening an image................ hiimgoodpack 2009 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago
--Things that you can change have been marked by *

local TweenService = game:GetService("TweenService") --Get Tween Service

local Gui = script.Parent --*The gui that we want to tween

local goal1 = {
    Rotation = 10 --*The Property Goal we want to change
}

local goal2 = {
    Rotation = -10 --*The reverse of Goal1
}

TweenTime = 2 --*The length of the tween

local tweenInfo = TweenInfo.new(TweenTime, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut) --Create a tweeninfo (TweenTime, Style, Direction)

local tween1 = TweenService:Create(Gui, tweenInfo, goal1) --Create the first tween (using properties goal1), (Instance, TweenInfo, Goal)
local tween2 = TweenService:Create(Gui, tweenInfo, goal2) --Create the second tween (using properties goal2)

spawn(function() --so code after this can run
    while true do --create a loop
        tween1:Play() --Play the first tween
        wait(TweenTime) --wait until the tween has finished
        tween2:Play() --do the second tween
        wait(TweenTime) --wait until second tween has finished
    end
end)

This should work if you put the local script inside of the guiobject or change the variable to where the gui is located

0
it works very good and fine thx ;DD !!! Lolamtic 63 — 6y
Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Use sine wave

part = script.Parent
x = 0
while wait() do
    y = 1*math.sin(x) -- change 1 to how high you want the sin wave to go on y axis
    part.CFrame = part.CFrame * CFrame.Angles(0,0,math.rad(y))
    x = x + 0.1
end

Just make sure script is inside the part, and i think this will work

0
Did you watch the gif the guy provided? hiimgoodpack 2009 — 6y
0
Yeah, i didn't realise this was for a gui, I though it was far a part with a decal on it. However the same concept can still apply to the gui... 123marble 61 — 6y

Answer this question