Im currently rewiting my turret and im tried it with the scripts i found on the forum but they dont work, the turret behaves really weird. In this video you can see that it doesnt work.
The current scripts ive been using
Client:
local function doHorizontalMathForRotate(MousePos,Base)
local baseToTargetVector = Base.Position - MousePos
local xAngle = math.deg(math.atan2(baseToTargetVector.Z,baseToTargetVector.X))-90 + Base.Orientation.Y
return xAngle
end
RunService.Heartbeat:Connect(function()
if InTank == true then
local mousePoint = Mouse.Hit.Position
local targetVector = (mousePoint - Mouse.Origin.Position).unit
local xAngle = doHorizontalMathForRotate(Mouse.Hit.Position,TankObj.Value.Turret.PrimaryPart)
TurretMovement:FireServer(TankObj.Value,xAngle)
end
end)
Server:
game.ReplicatedStorage.TurretMovement.OnServerEvent:Connect(function(plr,Tank,TurretMovement)
if Tank == script.Parent.Tank then
if TurretMovement then
Turret.TurretRootPart.HingeConstraint.TargetAngle = math.deg(TurretMovement)
end
end
end)