Trying to make turret

I want to make a turret that rotates to mouse position like in this vid:

All im asking for is just some tips/methods that i could use, i already tried sending mousePos to server and using :LookAt() but it was laggy and not reliable

Check the mouse’s position, change the turrets rotation property accordingly.

its okay now but i got problem when my cursor is on turret this happens:

and this is my code:

local uis = game:GetService("UserInputService")

local runs = game:GetService("RunService")

local player = game.Players.LocalPlayer

local camera = workspace.CurrentCamera

local mouse = player:GetMouse()

local TestCannon = game.Workspace.TestCannon

runs.Heartbeat:Connect(function()

local mousePos = mouse.Hit

TestCannon:SetPrimaryPartCFrame(CFrame.lookAt(TestCannon.PrimaryPart.Position,mousePos.Position))

end)
2 Likes

One thing you can do is check if the mouse.Hit is within certain radius of the turret’s position and if it is, don’t bother setting it’s cframe

i tried but then if i will move cursor to another side of cannon it will rotate insta and it will look ugly like teleporting

You can set Mouse.TargetFilter to the turret model and it will be ignored on Mouse.Hit

2 Likes

oh thanks thats useful info i never knew it existed