Hi, I made a gun reload animation with a Motor6D but I am struggling to play it, I followed tutorials but they did not work. Another question I also have is would it be on the client or server side?
I am unsure of how you would do this using the new Animator | Roblox Creator Documentation object, as I learned it using the Humanoid | Roblox Creator Documentation method. However, because this is now depreciated you should learn it using the Animator
object. Using Animations | Roblox Creator Documentation is what you’ll want to read to achieve this.
function Clerp(a,b,t)
local function QFCF(cf)
local mx,my,mz,m00,m01,m02,m10,m11,m12,m20,m21,m22 = cf:components()
local trace = m00 + m11 + m22
if trace > 0 then
local s = math.sqrt(1 + trace)
local recip = 0.5/s
return (m21 - m12) * recip,(m02 - m20) * recip,(m10 - m01) * recip,s * 0.5
else
local i = 0
if m11 > m00 then
i = 1
end
if m22 > (i == 0 and m00 or m11) then
i = 2
end
if i == 0 then
local s = math.sqrt(m00 - m11 - m22 + 1)
local recip = 0.5/s
return 0.5 * s,(m10 + m01) * recip,(m20 + m02) * recip,(m21 - m12) * recip
elseif i == 1 then
local s = math.sqrt(m11 - m22 - m00 + 1)
local recip = 0.5/s
return (m01 + m10) * recip,0.5 * s,(m21 + m12) * recip,(m02 - m20) * recip
elseif i == 2 then
local s = math.sqrt(m22 - m00 - m11 + 1)
local recip = 0.5/s return (m02 + m20) * recip,(m12 + m21) * recip,0.5 * s,(m10 - m01) * recip
end
end
end
local function QTCF(px,py,pz,x,y,z,w)
local xs,ys,zs = x + x,y + y,z + z
local wx,wy,wz = w * xs,w * ys,w * zs
local xx = x * xs
local xy = x * ys
local xz = x * zs
local yy = y * ys
local yz = y * zs
local zz = z * zs
return CFrame.new(px,py,pz,1 - (yy + zz),xy - wz,xz + wy,xy + wz,1 - (xx + zz),yz - wx,xz - wy,yz + wx,1 - (xx + yy))
end
local function QS(a,b,t)
local cosTheta = a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4]
local startInterp,finishInterp;
if cosTheta >= 0.0001 then
if (1 - cosTheta) > 0.0001 then
local theta = math.acos(cosTheta)
local invSinTheta = 1/math.sin(theta)
startInterp = math.sin((1 - t) * theta) * invSinTheta
finishInterp = math.sin(t * theta) * invSinTheta
else
startInterp = 1 - t
finishInterp = t
end
else
if (1 + cosTheta) > 0.0001 then
local theta = math.acos(-cosTheta)
local invSinTheta = 1/math.sin(theta)
startInterp = math.sin((t - 1) * theta) * invSinTheta
finishInterp = math.sin(t * theta) * invSinTheta
else
startInterp = t - 1
finishInterp = t
end
end
return a[1] * startInterp + b[1] * finishInterp,a[2] * startInterp + b[2] * finishInterp,a[3] * startInterp + b[3] * finishInterp,a[4] * startInterp + b[4] * finishInterp
end
local qa = {QFCF(a)}
local qb = {QFCF(b)}
local ax,ay,az = a.x,a.y,a.z
local bx,by,bz = b.x,b.y,b.z
local _t = 1 - t
return QTCF(_t * ax + t * bx,_t * ay + t * by,_t * az + t * bz,QS(qa,qb,t))
end
loca sine = 0
local rightarmc0 = CFrame.new(-.5,0,0) * CFrame.Angles(math.rad(0),math.rad(90),math.rad(0))
while wait() do
sine = sine + 1
ArmMotor6D.C0 = Clerp(ArmMotor6D.C0,rightarmc0 * CFrame.new() * CFrame.Angles(math.rad(0),math.rad(sine/10),math.rad(0)),1)
end
am using CFrameLerp in my animations
I am very confused as to what this script does?
u can use in looped animations
but u should know CFrame and CFrame.Angles
yeah but how would I implement this in my script?
mouse.Button1Down:Connect(function()
if gun.Ammo.Value > 0 then
Event:FireServer(gun.Handle.Position,gun.Handle.Orientation, mouse.Hit.p)
shotSound:Play()
gun.Ammo.Value = gun.Ammo.Value - 1
else
local reloadDebouce = gun.reloadDebouce
if reloadDebouce.Value == false then
reloadDebouce.Value = true
-- I want to play ani here
reload:play()
reload.Ended:Wait()
gun.Ammo.Value = 6
reloadDebouce.Value = false
end
end
end)
of course you can, just learn CFrames
I don’t think Cframes have something to do with motor6d animations
How did you do it with the Humanoid?
With the humanoid you just had to do something like this:
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://" .. animationId -- the animation id
animation = humanoid:LoadAnimation(animation) -- returns an AnimationTrack object
animation:Play() -- play the loaded animation
Still. You should use the new way. It’s honestly pretty much the same and just adds an extra step, which is to find the Animator
. It can be done like this:
local animator = humanoid:WaitForChild("Animator") -- the Animator for the humanoid
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://" .. animationId -- the animation id
animation = animator:LoadAnimation(animation) -- returns an AnimationTrack object ** we've replaced humanoid:LoadAnimation with animator:LoadAnimation
animation:Play() -- play the loaded animation