Hello,
So I’ve started making my own tanks system and ran into a big issue.
My tank turret rotates the wrong way. Which would be shown in the picture below.
It’s supposed to rotate around the TurretHolder part, I’m sure you guys know how a tank turret works.
So, what would the solution to that be? Here’s the local script too.
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local Motor = workspace:WaitForChild("M1 Abrams"):WaitForChild("Turret"):WaitForChild("TurretHolder"):FindFirstChildWhichIsA("Motor6D")
local Mouse = Players.LocalPlayer:GetMouse()
local DegPerSec = 5
local radPerSec = math.rad(DegPerSec)
local lookVec = CFrame.new(Motor.Parent.Position, Mouse.Hit.Position).LookVector
local currentAngle = math.atan2(lookVec.X, lookVec.Z)
RunService.Heartbeat:Connect(function(delta)
local targetDir = Motor.Parent.Position-Mouse.Hit.Position
local targetAngle = math.atan2(targetDir.X, targetDir.Z)
local difference = targetAngle-currentAngle
local angleToAdd
if math.abs(difference) > math.pi then
angleToAdd = -math.sign(difference)*(math.abs(difference)-math.pi)
else angleToAdd = difference
end
angleToAdd = math.clamp(angleToAdd, -radPerSec*delta, radPerSec*delta)
Motor.C0 *= CFrame.Angles(0, angleToAdd, 0)
currentAngle += angleToAdd
end)
All answers are appreciated.