The problem is that the order you do these things in matters a lot, since matrix multiplication is not commutative.
In order to "undo" an operation, it needs to be done precisely before the last. E.g., if x and y are the "forwards" and X and Y are the opposites (the undos), then x * y * X * Y won't work -- you have to do x * y * Y * x -- only then can the y * Y cancel out.
Since you're doing
a b c a b c a b c ... a b c, you have to undo with C B A C B A C B A ... C B A
That just means flipping the order of the three rotations in the second loop.
for i = 1,10 do
RS.C0 = RS.C0 *CFrame.Angles(0,0,.08)
RS.C0 = RS.C0 *CFrame.Angles(0,.04,0)
RS.C0 = RS.C0 *CFrame.Angles(.04,0,0)
wait(.01)
end
wait(1)
for i = 1,10 do
RS.C0 = RS.C0 *CFrame.Angles(-.04,0,0)
RS.C0 = RS.C0 *CFrame.Angles(0,-.04,0)
RS.C0 = RS.C0 *CFrame.Angles(0,0,-.08)
wait(.01)
end
Remember that wait(.01) will actually be waiting at least .03 seconds!
A different way to approach this would be to simply save every CFrame and go backwards through them -- setting, not multiplying:
local history = {}
for i = 1,10 do
RS.C0 = RS.C0 *CFrame.Angles(0,0,.08)
RS.C0 = RS.C0 *CFrame.Angles(0,.04,0)
RS.C0 = RS.C0 *CFrame.Angles(.04,0,0)
table.insert(history, RS.C0)
wait(.01)
end
for i = #history, 1, -1 do
RS.C0 = history[i]
wait(.01)
end
2 comments
oops you did not put your code in lua block correctly
yeah i fixed that now