The red part is the barrel’s lookvector projected
The white part is the position of the mouse hit
You can see the offset in position. It grows the further you are from the center. What causes this.
direction = (mantle.Position - mousehitpos).unit --mantle is the part connecting/between the turret and the barrel
directionflat = direction * Vector3.new(1,0,1)
targetelevation = math.deg(math.acos(direction:Dot(directionflat)))
mantleweld.C0 = CFrame.Angles(math.rad(targetelevation), 0, 0)
I tried your code and replicated the same issue you have. I’m not 100% why it would be doing that. It could be the offset from the mantle and the mouse position is giving you the illusion that the angle is the right elevation.
I swapped your code out for this and got more consistent and accurate results.
local elevation = math.asin(mouse.Hit.Position.Unit.Y)
weld.C0 = CFrame.Angles(elevation, 0, 0)