Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make the mouse go in a full circle and not create negative degrees?

Asked by 2 years ago

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

01local player = game:GetService("Players").LocalPlayer
02local mouse = player:GetMouse()
03local hinge = workspace.mover:WaitForChild("HingeConstraint")
04local runService = game:GetService("RunService")
05 
06local mouseang
07local degree
08 
09runService.RenderStepped:Connect(function()
10 
11    mouseang = -math.asin((mouse.Hit.Position).Unit.X)
12    degree = math.deg(mouseang)
13    print(degree)
14    hinge.TargetAngle = degree
15 
16end)

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?

0
doesn't the Hinge have LimitsEnabled property enabled? imKirda 4491 — 2y
0
No I didn't enable limits bestshot123 38 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

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

01local player = game:GetService("Players").LocalPlayer
02if player then
03    player.CharacterAdded:Wait()
04    wait()
05end
06 
07    local mouse = player:GetMouse()
08    if mouse then
09        print("yes")
10    end
11    local target = player.Character.HumanoidRootPart
12    local primary = workspace.Model.Primary
13 
14    game:GetService("RunService").Heartbeat:Connect(function()
15        local mouseP = mouse.Hit.Position
View all 22 lines...

Perfect for making turrets and works well no need to over do it :/

Ad

Answer this question