Tank aiming is not fully aligned with mouse

Hello, I’m researching how to make a tank system, I’m a beginner with each task it gets more broken and broken. So I made a junky script that gets the mouse position but there’s a little problem, it is not accurate at all
Here’s the script:

local mouseAiming = RS.Heartbeat:Connect(function()
				local point = CFrame.new(camera.CFrame.Position,mouse.Hit.LookVector+ camera.CFrame.Position)

				local x,y,z = point:ToOrientation()

				local posX= math.deg(y)*-1 
				
				local posY = math.deg(x)

				if freecam == false then
					turretremote:FireServer(posX)
					manletremote:FireServer(posY)
				end

			end)

Here how it looks right now:

I will be really thankful if someone could help me out,.

Improved accuracy with using PointToObjectSpace because of the offset between the camera and barrel which makes it inaccurate.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.