Setting camera offset in relation to a part with rotational aspect

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.


image
Notice that the center of the screen (mouse) is underneath or above the gun when aiming.

I tried to visualize the offset vector here.
image

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.
image
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”.

2 Likes

have you tried :ToObjectSpace()?

Hello, yes. The offset CFrame is already relative to the head.CFrame’s objectspace. Unfortunately, after looking it up there is no way to rotate the offset axes of the humanoid camera offset, so unfortunately this is not possible

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.