So, for my FPS Framework, I want to make automated Aim Downs Sights, i.e., without using an animation.
The issue is that I have to move the:-
- Arms
- Weapon
But I can’t do that without welding the arms to the weapon, but I need the arms welded to the RootPart instead.
So I took a rig and started experimenting, and I came up with a solution!
- An anchored part will be taken as the camera(this is just for testing purposes)
- The RootPart will be welded to the CameraPart
- There will be a AimPart which defines where the camera should be in order to make the player feel like they are aiming down sights.
And I came up with this
local AimPartPosition = (Camera.CFrame:inverse() * AimPart.CFrame).Position
CamWeld.C0 = CamWeld.C0 * CFrame.new(Vector3.new(-AimPartPosition.X,-AimPartPosition.Y,-AimPartPosition.Z))
Here, I get the offset of the AimPart from the CameraPart, and then reverse the position and finally apply that to the offset of RootPart to CameraPart.(The reason I put .Position is because I only want to reverse the Position and not the Rotation, just to be safe).
This works very well and I am proud I did it, but I feel like not using that extra CameraPart. I want to use RAW CFrame values instead of Motor6Ds.
This obviously wouldn’t work…
local AimPartPosition = (Camera.CFrame:inverse() * AimPart.CFrame).Position
RootPart.CFrame = Camera.CFrame:inverse() * RootPart.CFrame * CFrame.new(Vector3.new(-AimPartPosition.X,-AimPartPosition.Y,-AimPartPosition.Z))
Because
RootPart.CFrame ~= Camera.CFrame:inverse() * RootPart.CFrame
I have the offset I need to apply to the RootPart, I just do not know how.