Hey, this is my first time asking for help on the DevForum, so I’m not really used to doing this. But here I go:
I am trying to make the FPS element of a game I am working on. What I need is to be able to ADS my gun, however where the gun is in relation to my ViewModel’s chest is determined by an idle animation I play that I called “Revolver_Hold”
Here is the code I am currently using:
local Weld:Motor6D = ViewModel:FindFirstChild("PsuedoHrpWeld",true)
local HandlePart:BasePart = ViewModelGun.Handle
local Head:BasePart = ViewModel.Head
local RShoulder:Motor6D = ViewModel.RightUpperArm.RightShoulder
local offset:CFrame = HandlePart.CFrame:ToObjectSpace(AimPart.CFrame)
function AimDownSights(ToggleBool:boolean)
local goal = ToggleBool and offset or CFrame.new();
Weld.C0 = goal
end
A Little Context To This
This is a very truncated version of EgoMoose’s ADS script from his tutorial, which you can find via this link: The First Person Element Of A First Person Shooter
The only difference is that EgoMoose controls the arm placement on the Gun’s model with CFrames in his code, whereas I do this via an Idle animation instead.
Some other context is that the Motor6D “PsuedoHrpWeld” is a weld that connects the ViewModel Head to a BasePart. This is not really important, as that basePart is only used to simulate an Arm Bobbing effect on the ViewModel, and the C0 and C1 of the Motor6D is not changed or used at all in that code. Every RunService.Stepped Frame, I update this BasePart to the Player’s Camera, and the C0 and C1 offset of the weld can change the offset the ViewModel’s Head has from the BasePart, and therefore the Player’s Camera.
Also, my ViewModel is an R15 Rig with all limbs minus the LowerTorso, both legs, and HumanoidRootPart. It is parented to the game.Workspace, and my ViewModelGun is parented to the ViewModel.
Anyway, Back To The Main Problem
Here is a picture of my gun at rest:
And here is a picture of my gun when ADS’ing
What is happening is the code is moving the Revolver up to Eye level somehow with CFrames. I don’t fully understand the calculations, but I DO know that the script is doing what it should.
Now, in EgoMoose’s case, this would fully move the AimPart to the ViewModel’s Head. However, I am using Animations to determine where the revolver and the hands should be placed in relation to the Head. Therefore, the script can’t fully move the revolver to the player’s head, because I don’t think that a Part’s CFrame takes into account its CFrame Offset caused by an Animation.
A Possible Solution I Have No Idea How To Do
My current theory is that I was searching up Motor6Ds on the Roblox Docs, and apparently they have a nifty property called Motor6D.Transform, which can tell you the offset a part has from another part when an animation is running. Therefore, I believe that since I can get the offset all the limbs have from one another, I can somehow use this to calculate what exactly the offset C0 and C1 of my PsuedoHrpWeld should be so that the AimPart on my Revolver model is exactly at the Player’s Camera.
However, I have no idea how to do this, because I am not a complete expert on CFrames. So that is why I am asking for help. Or, if you think there is a solution to this problem that has literally nothing to do with my theory, then feel free to pitch that idea too. I’m all ears.
Thank you, and have a good day