Help with cframe lerp aiming

  1. What do you want to achieve?
    i wanna make an actual aiming for viewmodel

  2. What is the issue?
    its just the aimcf moving not the viewmodel arm,gun and etc

local aiming = false

run.RenderStepped:Connect(function()
	mouse.TargetFilter = cam

	if vm then
		if aiming then
			aiming = true
			for i = 0,1,.01 do
				wait()
				vm.aimcf.CFrame = vm.aimcf.CFrame:Lerp(vm.HumanoidRootPart.CFrame, .5)
			end
		end
	end
end)

mouse.Button2Down:Connect(function()
	aiming = true
end)

mouse.Button2Up:Connect(function()
	aiming = false
end)

Can you provide a screenshot or video describing the issue or the layout of your viewmodel, its pretty difficult to imagine what exactly is going wrong with a CFrame when we don’t know what the desired result is.

1 Like

its a little bit hard to give a right answer with the little information that you have given, however i believe the problem is that 1 you are changing the vm.aimcf cframe instead of the viewmodel cframe, and 2 you are lerping the vm.aimcf with the vm.HumanoidRootPart, instead you should do

vm.HumanoidRootPart.CFrame = vm.HumanoidRootPart.CFrame:Lerp(vm.aimcf.CFrame,i)

you should also use i for the delta instead of .5 otherwise the lerp won’t look smooth.
Also you may want to try a different aproach to your lerping method because you are running the for loop every frame which means that it will reset every frame. In this forum post there is an aiming function which you may find useful

1 Like
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local vm = character:Clone()
vm.Parent = workspace --change to correct parent instance
local aimcf = vm:WaitForChild("aimcf")
local hrp = vm:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local run = game:GetService("RunService")
local cam = workspace.CurrentCamera
local aiming = false

run.RenderStepped:Connect(function()
	mouse.TargetFilter = cam
	if character then
		if aiming then
			for i = 1, 100 do
				task.wait()
				aimcf.CFrame = aimcf.CFrame:Lerp(hrp.CFrame, i/100)
			end
		end
	end
end)

mouse.Button2Down:Connect(function()
	aiming = true
end)

mouse.Button2Up:Connect(function()
	aiming = false
end)

I had to make up instances but feel free to change those to the correct ones.

1 Like