I’ve been working on this T72B3 model recently, and have been having a lot of issues working out the turret.
Here’s my code for reference:
--MODULE:
local m={}
m.TurnTargetAngle = function(target: Vector3,origin: Vector3)
local delta = target - origin
local new_delta = Vector3.new(delta.x, 0, delta.z)
local unit_delta = new_delta.unit
local angle = math.atan2(unit_delta.z, unit_delta.x)
return (-math.deg(angle)+math.pi)
end
return m;
--SCRIPT:
coroutine.resume(coroutine.create(function()
RunService.Heartbeat:Connect(function()
if currentdriver ~= nil then
local MP = MousePosition:InvokeClient(game.Players[tostring(currentdriver)])
local t = TargetModule.TurnTargetAngle(MP,Parts.TurretRing1.Position)
Parts.TurretRing2.Rotator.TargetAngle = t
end
end)
end))
I would love to help you but cannot see what the problem is from the images shown.
I believe the turret simply turns round eg has no tilt so images showing the view from above would show more about the rotation issue.
Can you provide one for me?
From what I can find it seems to be due to the fact that math.atan2 is relative to the positive world X axis. I’m no vector math genius so my solution is to mess around with negatives and subtracting rotation and stuff
Edit: I solved it by subtracting the WorldOrientation.Y of the Attachment0 of the turret base servo
When I try to subtract the angle by (A0.Y-TargetAngle) it comes out to some absurd number.
When I try subtracting (A0.Y-TargetAngle) by the angle I get a weird assortment of random numbers.
I’m trying a few other methods and editing this as I go, but so far nothing has worked.
AS OF NOW THIS IS WHAT IT LOOKS LIKE:
SCRIPT:
RunService.Heartbeat:Connect(function()
if currentdriver ~= nil then
local MP = MousePosition:InvokeClient(game.Players[tostring(currentdriver)])
local t = TargetModule.TurnTargetAngle(MP,Parts.TurretRing2.Armor.WorldPosition,(Parts.TurretRing2.Rotator.Attachment0.WorldOrientation.Y))
Parts.TurretRing2.Rotator.TargetAngle = t
end
end)
MODULE:
local m={}
m.TurnTargetAngle = function(target: Vector3,origin: Vector3, sa)
local delta = target - origin
local new_delta = Vector3.new(delta.x, 0, delta.z)
local unit_delta = new_delta.unit
local angle = math.atan2(unit_delta.z, unit_delta.x)
print(sa-(-math.deg(angle)+math.pi))
return sa-(-math.deg(angle)+math.pi)
end
return m;