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

Creating smooth part rotation and animation?

Asked by
Nickoakz 231 Moderation Voter
9 years ago

I have tried making a smooth animation that will always start smooth and stop smooth. When I try to go from 0 to 180, it stops quicker then how it started. In the reverse, it starts quicker then how it stops.

function STRotate(to,speed,set,con)
    local to=to
    local from=set.Rotation
    local doNEG=1
    if from>=to then doNEG=-1 print("fliper") end
    local sin,rad=math.sin,math.rad
    for i = from,to,doNEG*4 do
        print(from + sin(rad(i))*(to - from),"--",from,i,to)
        set.Rotation = from + sin(rad(i))*(to - from)
        wait()
    end
    wait(6)
end

while wait() do
    print("ONE")
    STRotate(90,.05,script.Parent.Frame.Back)
    print("TWO")
    STRotate(0,.05,script.Parent.Frame.Back)
end

EDIT: I now have a different code, but for some random reason, I can't make it stop getting a really big negative number on the first three results.

-- For all easing functions:
-- t = time == how much time has to pass for the tweening to complete
-- b = begin == starting property value
-- c = change == ending - beginning
-- d = duration == running time. How much time has passed *right now*
local function inOutBack(t, b, c, d, s)
  s = (s or 1.70158) * 1.525
  t = t / d * 2
  if t < 1 then return c / 2 * (t * t * ((s + 1) * t - s)) + b end
  t = t - 2
  return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b
end

function STRotate(to,speed,set,con)
    local from=set.Rotation.Z
    print(from.."----"..to)
    if from>to then
        local holdfrom=from
        local holdto=to
        to=holdfrom
        from=holdto
    end
    local timer=4
    for i = 1,timer,.05 do
        local num=inOutBack(timer,from,from-to,i)
        print(timer," \ ",from," \ ",from-to," \ ",i," \ ",num)
        script.Parent.Rotation=Vector3.new(0,0,num)
        wait(.1)
    end
    wait(2)
end

while wait() do
    print("ONE")
    STRotate(20,.01,script.Parent)
    print("TWO")
    STRotate(80,.01,script.Parent)
end

Answer this question