hello, i’m starting to make a First person shooter game, but i ran into a problem with gun movement, i have a script which moves you hand up and down on y axis depending on mouse position, how ever, when i look down the gun moves too far from the camera and when i look up its too close
here is what i mean by looking up and down:
here is the script i used for my hand movement
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local PlayerMouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Arm = Character:WaitForChild("RightUpperArm")
local Shoulder = Arm:WaitForChild("RightShoulder")
local ShoulderOriginC0 = Shoulder.C0
RunService.RenderStepped:Connect(function()
local CameraCFrame = Camera.CoordinateFrame
if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then
local ArmLookVector = Arm.CFrame.lookVector
local HeadPosition = Head.CFrame.p
if Shoulder then
if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then
local Point = PlayerMouse.Hit.p
local Distance = (Head.CFrame.p - Point).magnitude
local Difference = Head.CFrame.Y - Point.Y
Shoulder.C0 = Shoulder.C0:lerp(ShoulderOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
end
end
end
end)
what could i do to fix this issue and have the gun stay the same distance from the camera no matter the direction you are looking at and is there a way i could change my script to R6 because its only R16 right now.