IT KINDA WORKS? BUT NOT REALLY? I’m a bit lost, but if I don’t clamp it works and aims, elsewise it kinda glitchilly goes to the side. (HumanoidRootPart facing forward it seems it splits from 180 to -180 in the middle. but math.clamp cannot work with the current numbers, its prob something I’m doing.
As @jody7777 said, you need to manipulate the relative vector. In other words, after you calculate the turret CFrame to aim at the character as you originally posted, convert it to the object space of the tank. Then adjust the CFrame based on your desired maximum and minimum angles, and then convert back to world space.
Of course, there is always more than one solution to any problem, so I am not saying others solutions are wrong. Let me know if my solution does not make sense!
Yeah, I kinda get what you mean, but I don’t think I understand enough to put that into practice effectively, it could just be my brain being tired too. I’ve been spending alot on other things trying to push out something before a self imposed deadline
Self imposed deadlines can be troublesome haha, I don’t know about you but I usually don’t give myself enough time because I am bad at guessing how long something will take…
I have to go to bed, but I will explain this in the morning if someone doesn’t beat me to it!
I found this identical post that explains two different solutions you can use. I was going to give you a detailed explanation, but they have already done it. If you have any questions, just ask!
You will have to do some basic tweaking of the code (obviously you aren’t aiming at the mouse, or using 90 degrees as your maximum angle). Also note, his first post of the code has a mistake that he fixes later on in a separate reply. You also do not have a “core”, so you won’t need that (you will have to adjust a few lines for that as well).
Worked like a charm, I also fixed the turret falling behind issue while doing this, now it doesn’t fall behind at all even when moving, is a bit problematic though because it sometimes snaps behind itself if you go right on the edges, but I can look into this, prob need to put a clamp or two.
local X, Y, Z = absoluteTurretCFrame:ToOrientation()
local X2, Y2, Z2 = absoluteTurretCFrame:ToEulerAnglesXYZ()
local ClampedY = math.clamp(Y,Y2 - 2,Y2 + 2)
Elsewise it works great and it correctly stops on angles.
Just this turning backwards things when standing on it may be problematic, oh and it doesn’t matter if your floating above it, as long as you’re standing above this area the clamp stops working correctly.
local absoluteTurretCFrame = CFrame.new(script.Parent.Body.TurretPos.Position, Players[i].Character.HumanoidRootPart.Position)
local Test = isInAngleRange(script.Parent.HumanoidRootPart.CFrame.p, script.Parent.HumanoidRootPart.CFrame.LookVector, Players[i].Character.HumanoidRootPart.Position)
if Test then
local X, Y, Z = absoluteTurretCFrame:ToOrientation()
local X2, Y2, Z2 = absoluteTurretCFrame:ToEulerAnglesXYZ()
local ClampedX = math.clamp(X,-0.2,0.2)
local ClampedY = math.clamp(Y,Y2 - 2,Y2 + 2)
trys to make tank turret function properly Tank: NECK SNAP SOUND
but in all seriousness, it works until that very specific spot in the middle is touched, then it goes full disco depending on where you walk. (Which I assume is the clamp stopping for some reason)
I can walk to its side, or its back without any issue.
Yeah, I tested it a bit earlier and it seems the X clamp doesn’t give out, it’s the Y clamp that gives out (It still clamps correctly for X even when Y is crying)