How could I go about adding an aiming mechanic to my gun system

Hello! I am working on a gun system for my game, and I want to know some ways (fairly simple) to add aiming, this is FE gun kit and I have heavily modified it, so there is a custom view model in the camera containing the arms, and weapon model, I want to use CFrame aiming where the viewmodels aimpart goes to the center of the camera but I don’t know how to; Heres a video on it so far, it’s the built-in aiming system with it, which is kind of bad,; Ignore the crosshair and wonky sounds and animations, I will fix it soon lol

Do you know the code that sets the viewmodel’s cframe?

Yeah I do its in one of the viewmodel scripts

If so, here’s the steps you should follow:

  1. Get the Offset of AimCF relative to Viewmodel’s PrimaryPart
  2. Make an bool dedicated to Aim, it will be true when aiming and false when not aiming
  3. When aiming, the viewmodel should be set to player’s camera based on the AimCF’s Offset

In final result, it will look something like this:

local Aiming = false

game.UserInputService.InputBegan:Connect(function(Input,Proc)
	if Proc then return end
	if Input.UserInputType == Enum.UserInputType.MouseButton2 then
		Aiming = true
	end
end)

game.UserInputService.InputEnded:Connect(function(Input,Proc)
	if Proc then return end
	if Input.UserInputType == Enum.UserInputType.MouseButton2 then
		Aiming = false
	end
end)

game:GetService("RunService").RenderStepped:Connect(function()
	local Model --Get the model
	local AimCF --Get the AimPart's CFrame

	local Offset = AimCF:ToObjectSpace(Model.PrimaryPart)

	if Aiming == true then
		Model:PivotTo(workspace.CurrentCamera.CFrame*Offset)
	else
		Model:PivotTo(workspace.CurrentCamera.CFrame)
	end
end)
1 Like

This is the non-animated version. If you want it to be animated then you can use a CFrameValue to hold the offset. Then animate them using tweens that will fire when you change the aiming boolean.

1 Like