I am part of a ROBLOX community that participates in tank battles. I've been tasked with converting the tank scripts to FilteringEnabled; I've been quite successful thus far. I managed to get the firing and reloading to work with FilteringEnabled. But my current issue is getting the turret and gun rotation to work.
This is inside a localScript inside a tool, and it works perfectly.
function setTurretDirection(elevation, rotation)
parts.MantletBase.MainGunWeld.C1 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0, elevation, 0);
parts.TurretRing2.TurretRingWeld.C1 = CFrame.new(0,0,0.8) * CFrame.fromEulerAnglesXYZ(0, 0, rotation);
end
function getSmoothRotation(rotations)
local targElev = rotations[1];
local targRot = rotations[2];
local maxGunDepression = Info.depression;
if math.abs(targElev) > maxGunDepression then
targElev = maxGunDepression*sign(targElev);
end
local elevDiff = targElev - currentElev;
if math.abs(elevDiff) < 0.01 then -- If they're close
currentElev = targElev;
else -- Move towards it
currentElev = currentElev + 0.01*sign(elevDiff);
end
local rotDiff = targRot - currentRot;
if rotDiff > math.pi then
rotDiff = rotDiff - 2*math.pi;
elseif rotDiff < -math.pi then
rotDiff = rotDiff + 2*math.pi;
end
local turretSpeed = Info.turretTraverse;
if math.abs(rotDiff) < turretSpeed then -- If they're close
currentRot = targRot;
else -- Move towards it
currentRot = currentRot + turretSpeed*sign(rotDiff);
end
local rotations = {};
rotations[1] = targElev;
rotations[2] = targRot;
return rotations;
end
currentElev = 0;
currentRot = 0;
while wait() do
if (myMouse) then
-- Position of mouse in world
mousePoint = myMouse.Hit.p;
targetVector = (mousePoint - parts.GunBase.CFrame.p).unit;
targetRotations = determineNewDirections(targetVector);
for i = 1, 4 do
newRotations = getSmoothRotation(targetRotations);
setTurretDirection(currentElev, currentRot);
wait();
end
end
end
However, with FilteringEnabled, it only works client-side; I understand this is how FilteringEnabled works. I also need to optimize it so that there's as little lag as possible. I've been told that I could just transfer the numbers I need to a Server Script and have the Server Script handle the actual rotation functions. But I don't know how I'd go about doing so.
