Lerp not functioning as intended

Hey everyone, so I’m implementing an aiming system for my fps framework, and you the lerping between the aiming cframe and the idle cframe isn’t working as intended.

Here’s my code (ripped from the rest of the script):

local equipOffset = self.settings[self.curwep].cframes.idle.start:lerp(self.settings[self.curwep].cframes.idle.finish, self.lerpValues.equip.Value)
finalOffset *= equipOffset

...

finalOffset = finalOffset:lerp(self.settings[self.curwep].cframes.aim.cframe, self.lerpValues.aim.Value)

Here, I’m using the same CFrame for both the idle cframe and the aiming cframe (check my settings module below, mainly for cframes.idle.start and cframes.aim.cframe):

module.cframes = {
	idle = {start=CFrame.new(0, -0.23, 0) * CFrame.Angles(0, math.rad(30), math.rad(30)), finish=CFrame.new(.08, -.13, .26), speed=0.9, damping=0.8},
	aim = {cframe=CFrame.new(.08, -.13, .26), speed = 1.8, damping=.8, shove=Vector3.new(.5, .3, 0)},
	sprint = {cframe=CFrame.new(2.5, -.2, -1.4) * CFrame.Angles(0, math.rad(60), math.rad(30)), speed = 2, damping=1}
}

However, when I try aiming, the gun just flies off the screen for whatever reason. Here’s a video showing the issue:

Not sure what I’m doing wrong here, so any help is appreciated!

Did a bit of testing and seems that the viewmodel goes to the world position of the CFrame, instead of the position on the camera, no idea why this is the case. Sorry if I sound impatient, but it feels like I’m doing something unnecessarily stupid here.

How are you applying finalOffset to the camera’s CFrame? Could we see more code?

Yeah, sure here

self.viewmodel:PivotTo(finalOffset)
-- Don't think any other lines are important here? self.viewmodel is inside the camera.
1 Like

The reason it’s going to the world CFrame is because you aren’t multiplying the offset to the camera’s CFrame. Try this:

self.viewmodel:PivotTo(workspace.CurrentCamera.CFrame * finalOffset)

Wait no really sorry for that, finalOffset is already defined as self.camera.CFrame (before offsets are applied):

local finalOffset = self.camera.CFrame

Nevermind, fixed it by just using finalOffset as a blank CFrame until manipulated, and using :ToWorldSpace() on the camera CFrame