Angle of mouse position (acos) is offset when applied to weld C0

4d4086217270c27d3e396c85d1cde7fa

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)

1 Like

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)

1 Like

ok ill switch to this, its working perfect so far but just in case lets see if anybody can breakdown what happened originally

direction * Vector3.new(1,0,1) isn’t a unit vector, you’re chopping off the Y length.

targetelevation = math.deg(math.acos(direction:Dot(directionflat.Unit)))

Would probably fix it. @MrNicNac’s solution is faster and better, though :slight_smile: