What do you want to achieve?
My character’s arms are continually lerped towards a mouse position and top of that I have animations with artificial sway to add more inaccuracy to the gun. For an aim down sights system, I am trying to set the humanoid’s CameraOffset in relation to the X, Y, and Z axes of an aim part through continual lerping by doing this calculation in a renderstepped loop,
local offset = aimpart.CFrame:ToObjectSpace(character.Head.CFrame)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(-offset.Position, 0.3)
What is the issue?
The offset works perfectly when aiming eye level, continually adjusting to changes in the position of the aim part in relation to the head, however there is an issue when aiming up and down.
Notice that the center of the screen (mouse) is underneath or above the gun when aiming.
I tried to visualize the offset vector here.
It seems to be adequate in working while facing forward but faces the issue when I aim up
The solution would be to pivot how the axes are calculated like this.
Is this possible? Is there a way to “Move” the camera relative to a part’s position, accounting for the continual rotation of the arms? Or to rotate its offset axes in relation with the head?
I am not looking for an artificial floating arms client viewmodel.
What solutions have you tried so far?
I have tried setting the camera to scriptable and setting the camera.CFrame to the aimpart.CFrame but it just leads to uncontrollable spinning and the camera can no longer be moved in first person. I have also tried changing the CameraSubject to the aim part which partially works but does not allow the player to “look around”.