local hinge = workspace.hingepart.HingeConstraint local p = hinge.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Move:Connect(function() local pos = p.Position local angleRad = math.asin((pos - mouse.Hit.p).unit.X) local angleDeg = math.deg(angleRad) hinge.TargetAngle = angleDeg end)
That script is supposed to get the angle between the position of a part and the position of my mouse, and set that angle to the targetangle of a hingeconstraint so that the part attached to the hinge "points" toward my mouse.
It works, but only half way. Check out this gif to see what I mean more clearly:
https://gyazo.com/281d39d833a9a6a8256488b033bffacb
As you can see, it works fine when my mouse is below the part, but when I move it above, it is inverted.
I've tried also using the dot product to get the angle between two vectors by using the steps outlined in this article, but I'm getting the same issue:
https://medium.com/@EgoMoose/the-scary-thing-known-as-the-dot-product-5124be3a66aa
Does anyone know how to get the angle between two vectors without this problem? Is there something I'm missing? Any help will be appreciated.