#Swiveling turret randomly pointing up/down

1 messages · Page 1 of 1 (latest)

atomic depot
#

I made this cool(ish) turret that points where your mouse is. It keeps randomly pointing towards the ground even though it's on a HingeConstraint.

--Script (Turret)
local Turret = script.Parent
local Body = Turret.Body

Body.Seat.ChildAdded:Connect(function(Child)
    if Child:IsA("Weld") then
        game.ReplicatedStorage.TurretSit:FireClient(game.Players:GetPlayerFromCharacter(Child.Part1.Parent))
    end
end)

game.ReplicatedStorage.MoveTurret.OnServerEvent:Connect(function(Player, Mouse)
    Body:PivotTo(CFrame.lookAt(Body.Seat.Position, Vector3.new(Mouse.X, 0, Mouse.Z), Vector3.new(0, 0, 1)))
end)

--LocalScript (StarterCharacterScripts)
local Hum = script.Parent.Humanoid

game.ReplicatedStorage.TurretSit.OnClientEvent:Connect(function()
    while Hum.Sit do
        local Mouse = game.Players.LocalPlayer:GetMouse()
        game.ReplicatedStorage.MoveTurret:FireServer(Mouse.Hit)
        task.wait(0.1)
    end
end)
#

Swiveling turret randomly pointing up/down

zealous basin
#

I think its because you're pivoting the body so that it always tries to look down towards zero. That is if the Body.Seat.Position.Y is not zero

#

Maybe this should work?
Body:PivotTo(CFrame.lookAt(Body.Seat.Position, Vector3.new(Mouse.X, Body.Seat.Position.Y, Mouse.Z), Vector3.new(0, 0, 1)))

atomic depot
#

trying it rn

#

works, thanks man!

#

wait, no, no it doesn't

#

huh.

#

friend solved

steady nebula
#

why are you using Vector3.new(0, 0, 1) as your up vector?

#

that's not up