Gun ADS CFraming from animations

Hello, I have been recently been working on my guns, and I’m working on the ADS.

However, these guns are not CFrame they use animations, and I do not have animations for first person or ADS.

I have a custom first-person script, and my current hacky way of doing an “ADS”, is by creating a CFrameValue in the tool which is then tweened with TweenService, and picked up by the first person script.

As you can see, it does “work” kinda but it looks quite scuffed.

https://gyazo.com/ee8cb49eb71ffa80d57db1d82d9f0a2c

		aim_Tween3 = TS:Create(FP_OffsetValue, TweenInfo.new(speed, Config.AimSettings.EasingStyle, Config.AimSettings.EasingDirection), {Value = Config.AimSettings.Offset})
		aim_Tween3:Play()

And this is how it looks in the config
Offset = CFrame.new(-0.58,0.3,0.9) * CFrame.Angles(math.rad(0.75),math.rad(0.8),0);

This is an overview of the problem I am having with the ADS:

Since it isn’t actually set to the camera and I’ve just had to manually try and get the best offset, it isn’t aligned properly and some guns look much worse.

What is the best way to fix this? Is it still possible to perfect it with an offset CFrame like so? This is the code in my FP script:

		local cF = viewModel.HumanoidRootPart.CFrame:Lerp(cam.CFrame:ToWorldSpace(CFrame.new(Vector3.new(0,-1.65,-1))),0.8)  --Lerps for smoothness
		if tool:FindFirstChild("FP_Offset") then
			cF = cF * CFrame.new(tool.FP_Offset.Value.X,tool.FP_Offset.Value.Y,tool.FP_Offset.Value.Z) 
		end
		if tool:FindFirstChild("FP_Offset2") then
			cF = cF * tool:FindFirstChild("FP_Offset2").Value
		end
		
		local swayTing = 1
		if tool:FindFirstChild("Values") and tool.Values:FindFirstChild("AimDown") and tool.Values.AimDown.Value then
			swayTing = 0.2
			currentRelPart = torso
		else
			currentRelPart = hrp
		end

		cF = cF * SwayModule.GetSwayCF(swayTing) 
		viewModel.HumanoidRootPart.CFrame = cF
5 Likes

If you want to consider making it smoother, checking the ToObjectSpace offset between the sight and the handle, then the handle to the camera might help.

I used something similar for my CFrame fps engine so I wouldn’t have to manually change those offsets.

1 Like

How would I do this? And is this like having a part inside the tool for the sight ADS CFrame?

1 Like

I did the ADS long time ago and I kinda forgot the details it but:

Basically what I’m doing is calculate the offset between the ADS part and the center of camera, this has to be done before hand and they’re stored inside my weapon configs. Then I tween my ViewModel arms’ Motor’s C0 and weapon motor by the offset (XYZ)

I also don’t recommend storing any values inside a weapon tool while a local script reference them, they can be easily changed by exploiters.

6 Likes

Yeah it seems due to the complexity of my custom viewmodel script I had to do it by trial and error and store the offset CFrame in the config module. Thanks!

1 Like