I’m working on a shooter game, in which all the tools force you into first person and make your actual characters arms follow the camera. The characters are R6 rigs.
I want to make it clear, that there are NO viewmodels being used, just the real, physical arms of your character that everybody sees.
Some tools are guns and can be aimed with.
When aiming, the left and right shoulders Motor6Ds C0 property should be changed in such a way, that the AimPart, which is inside and welded to the tool, is perfectly aligned with the camera.
While the AimPart is mostly behind the sights of the gun, it shouldn’t matter where it’s positioned. The script should always move the arms, so the AimPart ends up at the camera, using the shoulders parented to the torso.
I’m having trouble calculating the Position of where the shoulders should be in WorldSpace.
I just need the calculated WorldPosition and Rotation. It gets converted into the torsos ObjectSpace afterwards.
Here’s how the code looks like right now:
local origin = rightArm.CFrame * CFrame.new(0, 1, 0)
local aimOffset = aimPart.CFrame:PointToObjectSpace(origin.Position)
local right_offset = camCF * CFrame.new(aimOffset) * CFrame.Angles(aimPart.CFrame:ToObjectSpace(camCF):ToEulerAnglesXYZ())
local left_offset = right_offset * CFrame.new(Vector3.new(-2, 0, 0))
rightShoulder.C0 = rightShoulder.C0:lerp(torso.CFrame:ToObjectSpace(right_offset) * CFrame.Angles(0, math.pi/2, 0), speed)
leftShoulder.C0 = leftShoulder.C0:lerp(torso.CFrame:ToObjectSpace(left_offset) * CFrame.Angles(0, -math.pi/2, 0), speed)
Anything below the declaration of aimOffset is i think fine. It’s just aimOffset and/or origin that needs to be changed.
There could be a solution that also changes the other stuff, so feel free to post it.
left_offset has to have that offset of (-2, 0, 0).
The arms have to point towards the direction your camera is facing.
I have searched for solutions to my problem on the developer forum, but found none that worked.
I have tried calculating it in many different ways, but none worked.