Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TweenObjectCFrame do
- local HalfPi= math.pi/2
- local acos= math.acos
- local sin= math.sin
- local cf= CFrame.new
- local Divide= cf().toObjectSpace
- local Components= cf().components
- local tick= tick
- local RenderStepped= game:GetService("RunService").RenderStepped
- local TweeningData= {}
- function TweenObjectCFrame(Object,Index,NextCFrame,Time)-- Object=
- if TweeningData[Object] and TweeningData[Object][Index] then
- TweeningData[Object][Index]:disconnect()
- end
- local LastCFrame= Object[Index]
- local x, y, z,
- xx,yx,zx,
- xy,yy,zy,
- xz,yz,zz= Components(Divide(LastCFrame,NextCFrame))
- local qw,qx,qy,qz
- local th
- local s
- local tr= xx+yy+zz
- if tr>2.99999 then
- s= 1
- th= 0.1
- qw,qx,qy,qz= 1,0,0,0
- elseif tr>-0.99999 then
- local m= 2*(tr+1)^0.5
- qw= m/4
- qx= (yz-zy)/m
- qy= (zx-xz)/m
- qz= (xy-yx)/m
- th= acos(qw)
- s= (1-qw*qw)^0.5
- else
- qw= 0
- qx= xx+yx+zx+1
- qy= xy+yy+zy+1
- qz= xz+yz+zz+1
- local m= (qx*qx+qy*qy+qz*qz)^0.5
- qx,qy,qz= qx/m,qy/m,qz/m
- th= HalfPi
- s= 1
- end
- local t0= tick()
- local RenderObject
- RenderObject=RenderStepped:connect(function()
- local t= (tick()-t0)/Time
- if t>1 then
- Object[Index]= NextCFrame
- RenderObject:disconnect()
- TweeningData[Object]=nil
- return
- end
- local s1= sin(th*t)/s
- Object[Index]= LastCFrame*cf(
- t*x,t*y,t*z,
- s1*qx,
- s1*qy,
- s1*qz,
- sin(th*(1-t))/s+s1*qw
- )
- end)
- TweeningData[Object]={
- [Index]=RenderObject;
- }
- end
- end
- return function(Object,Index,NextCFrame,Time)
- TweenObjectCFrame(Object,Index,NextCFrame,Time)
- end
Advertisement
Add Comment
Please, Sign In to add comment