0

So because I can't visualize it like other people can: How do I fix my turret problems?

Edited 22 days ago

*So I'm working on this game, right? And I need to make a turret rotate with this particular style of code, in otherwords I'm trying to stay within our game's standard.

Here is the problem though:*

-- X
for i = 1,2 do
local turret = sp:FindFirstChild("Turret"..i)
local hinge = turret.TurretConstraint
local x, y, z = CFrame.new(hinge.Attachment0.WorldPosition * Vector3.new(1, 0, 1), mouse.Hit.p * Vector3.new(1, 0, 1)):toEulerAnglesXYZ()
local ang = math.abs(math.floor(math.deg(x))) >= 180 and 180 - math.deg(y) or math.deg(y)
hinge.TargetAngle = (ang > 180 and -360 + ang or ang) - sp.Torso.Orientation.Y

end
end

wait()
end



*This works perfectly fine for the X-Z Rotation of the turret; I saw somewhere that this is called a 1D turret as it doesn't move up and down.

However, when I go to flip the axis to get up and down/tilt for the turret's BARREL, it works only to some extent.*

-- Y
for i = 1,2 do
local barrel = sp:FindFirstChild("Barrel"..i)
local hinge = barrel.BarrelConstraint
local x, y, z = CFrame.new(hinge.Attachment0.WorldPosition * Vector3.new(0, 1, 1), mouse.Hit.p * Vector3.new(0, 1, 1)):toEulerAnglesXYZ()
local ang = math.abs(math.floor(math.deg(y))) >= 180 and 180 - math.deg(y) or math.deg(x)
hinge.TargetAngle = (ang > 180 and -360 + ang or ang) - sp.Torso.Orientation.X


Heres a link showing what the problem looks like: https://i.gyazo.com/1231ce2d2319c0407d53e0e63b7037dd.gif

When I look down a specific axis ( in this case the ZED axis ) my turret flips.

I personally wish I could see the problem but I can't, because I know this has to do with circles in programming and because I can't see the end result until I press play it slows me down and I'm left confused.

0
your game needs a better style of code. I'd suggest keep changing the x and y and z and try to get a better result, something might click in your brain and it would work. preferably the TargetAngle or the ang greatneil80 2641 — 22d