Hello! so I was trying to make a rotatable part that you can spin Left or Right with your mouse. I am having trouble getting the part to spin full 360 and it keeps glitching and wanting to point towards the ground if anyone could possibly help me I would appreciate it!
local mouse = game.Players.LocalPlayer:GetMouse()
local part = workspace.TEST
local click = false
mouse.Button1Up:Connect(function()
click = false
end)
mouse.Button1Down:Connect(function()
click = true
end)
mouse.Move:Connect(function()
if click == true then
part.CFrame = CFrame.new(part.Position, Vector3.new(mouse.Hit.X, 0,0,0)) else
if click == false then
return click
end
end
end)
I have tried something like this, it does in fact fully rotate but when you move the mouse in a circle sometimes it snaps back and fourth and doesn’t really rotate in a perfect circle if that makes sense?
I need it like this https://gyazo.com/4649ee7cf3384c8f93012bd12c544ffa
If your trying to achieve that rotation effect your going to need an entire different approach as currently your following the mouse not using it to rotate.
Perhaps you should try projecting your part’s position to a world point on screen, and subtracting the distance between the initial world point (from top left corner of screen), and your mouse vector coordinates X and Y. This will return an offset between the world point coordinates and mouse coordinates. Using atan2, you can convert this offset directly to a radian which can be used to rotate the part on an axis. Hope this helps
Yes! thank you it works this is what I was looking for I never knew you had to use WorldToScreen because I had already tried CFrame angles but it didn’t work.