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 1 year 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

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?

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

1 answer

Log in to vote
1
Answered by 1 year 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

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 :/

Ad

Answer this question