Im trying to make a turret system where the seat will follow the mouse rotation, however the mouse doesn't seem to make a full circle in degrees 0-360 instead it goes from 90 to -90. Im using a hinge so i have to convert the mouse pos to degrees. How would I prevent the mouse degrees from going negative and instead make it follow the 0-360
Code
local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local hinge = workspace.mover:WaitForChild("HingeConstraint") local runService = game:GetService("RunService") local mouseang local degree runService.RenderStepped:Connect(function() mouseang = -math.asin((mouse.Hit.Position).Unit.X) degree = math.deg(mouseang) print(degree) hinge.TargetAngle = degree end)
Here is a video of whats happening
https://media.giphy.com/media/NTyexgTq6AZFpPdN9Y/giphy.gif
How would I make it so it goes around the back too?
Answering my own question: if anyone comes across this problem I found out you could just make the part.CFrame follow your mouse.Hit.P
local player = game:GetService("Players").LocalPlayer if player then player.CharacterAdded:Wait() wait() end local mouse = player:GetMouse() if mouse then print("yes") end local target = player.Character.HumanoidRootPart local primary = workspace.Model.Primary game:GetService("RunService").Heartbeat:Connect(function() local mouseP = mouse.Hit.Position print(mouseP) local FromV3 = primary.CFrame.Position local ToV3 = mouseP primary.CFrame = CFrame.new(FromV3, ToV3) end)
Perfect for making turrets and works well no need to over do it :/