I’m trying to make a 2.5D gun system. My only problem is that the gun is definitely not aligned with the actual mouse. It is somewhat fine on longer distances, but trying to aim near the character is definitely not acting as it is supposed to.
The first picture is me aiming a relatively long distance (looks relatively okay), and the second one is me aiming a relatively short distance (visible that something is wrong).
I was wondering, is there a better way to capture the mouse position, that would fit this task better? Currently, I am using UserInputService:GetMousePosition()
Full script (that moves the hands and the head):
local RunService = game:GetService(“RunService”)
local UIS = game:GetService(“UserInputService”)
local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild(“Torso”)
local Torso = character.Torso
local RightShoulder = Torso[“Right Shoulder”]
local jointWorldPos = RightShoulder.Part0.Position
local camera = workspace.CurrentCamera
local remote = game.ReplicatedStorage.MouseFollowFunctionRemoteEvent
RunService.RenderStepped:Connect(function()
local mousePos = UIS:GetMouseLocation()
local jointScreenPos = camera:WorldToViewportPoint(jointWorldPos)
local delta = mousePos - Vector2.new(jointScreenPos.X, jointScreenPos.Y)
if delta.Magnitude < 1 then return end
local angle = math.atan2(-delta.Y, delta.X)
remote:FireServer(angle)
end)

