So...I've been messing around with this for...months on/off and I still can't figure out how to create a simple transitional animation for rotating a model...I have come to the following script as a result which looks quite hideous and I'm wondering if there is any way to make a shorter/more efficient version?
Feel free to copy and run the script to see what I'm trying to accomplish. It works. But, it's hideous. And I do want to know if there is a better/more efficient way.
Script Starts Below
[ The following script was pulled from a trash can, but works ]
=======================================================================
model = script.Parent
mainPart = model.MainPart
function rotateBy(model, center, rot, origin)
for _, p in pairs(model:children()) do
if p:IsA("BasePart") then
p.CFrame = origin[p]
end
end
for _,object in pairs(model:children()) do
if object:IsA("BasePart") then
object.CFrame = rot:toWorldSpace(center:toObjectSpace(object.CFrame))
end
rotateBy(object, center, rot)
end
end
function timeBy(model, mainPart, rot)
cframe = mainPart.CFrame
origin = {}
for _, turn1 in pairs(model:children()) do
if turn1:IsA("BasePart") then
origin[turn1] = turn1.CFrame
end
end
x = 0
y = 0
z = 0
x1 = false
y1 = false
z1 = false
if rot.X < 0 then
x1 = true
end
if rot.Y < 0 then
y1 = true
end
if rot.Z < 0 then
z1 = true
end
for i = 0, math.abs(rot.X+rot.Y+rot.Z) do
print(i)
wait()
x = x1 and -i or i
y = y1 and -i or i
z = z1 and -i or i
abx = math.abs(x)
aby = math.abs(y)
abz = math.abs(z)
last = false
if abx >= math.abs(rot.X) and aby >= math.abs(rot.Y) and abz >= math.abs(rot.Z) then
last = true
end
if abx >= math.abs(rot.X) then
x = rot.X
end
if aby >= math.abs(rot.Y) then
y = rot.Y
end
if abz >= math.abs(rot.Z) then
z = rot.Z
end
if last then
x = rot.X
y = rot.Y
z = rot.Z
end
rotateBy(model, cframe, cframe * CFrame.Angles(math.rad(x),math.rad(y),math.rad(z)), origin)
print(x,y,z)
end
end
timeBy(model, mainPart, Vector3.new(0,90,0))
wait(2)
timeBy(model, mainPart, Vector3.new(0,90,0))
wait(2)
timeBy(model, mainPart, Vector3.new(0,90,0))
wait(2)
timeBy(model, mainPart, Vector3.new(0,90,0))
wait(2)
timeBy(model, mainPart, Vector3.new(0,90,0))
=======================================================================
|