I have reviewed numerous related topics, none of them sadly resolved the issue.
The issue is the discrepancy between the intended aim of a mobile gun and its actual firing position upon clicking the fire button. Ideally, the script should direct gunfire toward the center of the screen, but instead, it aligns with the screen’s position where the fire button is tapped.
local newRay
local part, position
if UserInputService.TouchEnabled then
local guiInset = game:GetService("GuiService"):GetGuiInset()
local centerScreen = Vector2.new(camera.ViewportSize.X / 2, (camera.ViewportSize.Y - guiInset.Y) / 2)
newRay = camera:ViewportPointToRay(centerScreen.X, centerScreen.Y)
newRay = Ray.new(newRay.Origin, newRay.Direction * 100)
part, position = workspace:FindPartOnRayWithIgnoreList(newRay, {character, workspace.Effects.BulletHoles}, false, true)
print("Origin:", newRay.Origin)
print("Direction:", newRay.Direction)
print("hit Part:", tostring(part))
print("Position:", tostring(position))
end
The printed output for reference:
Any help or insights would be greatly appreciated.