I am trying to make an aim animation. I want to slowly change the CFrame of the gun holding to the neww CFrame with Lerp. But I dont know how. I tried doing this:
local loadout = {
Primary = "M4";
Secondary = "M9";
Meele = "Knife";
}
aimcf = CFrame.new()
local primarymodule = require(reps.GunModules[loadout.Primary])
local primary = guns[loadout.Primary]:Clone()
primary.Parent = cam
aiming = false
run.RenderStepped:Connect(function()
if aiming == false then
primary:SetPrimaryPartCFrame(cam.CFrame * primarymodule.CameraPosition)
elseif aiming then
aimcf = aimcf:lerp(primarymodule.CameraPositionAim,.1)
primary:SetPrimaryPartCFrame(cam.CFrame)
end
end)
mouse.Button2Down:Connect(function()
aiming = true
print("down")
end)
mouse.Button2Up:Connect(function()
aiming = false
print("up")
end)
When I write the code like this, the gun just gets CFramed upwards, and it supposed to be close to my face seeing the scope (duh). When I remove the 19th line - primary:SetPrimaryPartCFrame(cam.CFrame), it just gets kind of unwelded from my Camera.. it stays in midair. When I release the button it goes back to the normal CFrame when I am not aiming.
How do I fix this so I will be able to smoothly aim and smoothly release the aim when I want to? I tried to fix this, read about Lerping but I cant get this right. Please help me.
