'Jittering' on a Motor6D

I’m attempting to make a tracking turret that will aim at a world position. At the moment the math is all correct, however I’ve come across an issue with the Motor6D.

For some reason when I test it it is ‘jittering’ between angles instead of smoothly interpolating to the next.

Currently I’m calculating and updating the angle each RunService.Stepped, and while the angle is printing correctly at a good rate, the turret is only moving every 15 or so Stepped frames.

local setAngle = function(ang, motor)
	if (not motor) then
		ang = math.max(ang, math.rad(-20))
		for _,gun in pairs(g) do
			gun[1]['Motor']:SetDesiredAngle(ang);
		end
	else
		m6:SetDesiredAngle(ang);
	end
end

local getAngle = function(pos)
	local newPos = turret.platform.CFrame:PointToObjectSpace(pos);
	-- Y = actual X; X = actual Y; Z = actual Z;
	local xzDist = Vector3.new(newPos.Y, 0, newPos.Z).magnitude;
	local vAng = math.atan2(newPos.X, xzDist);
	local hAng = math.atan2(newPos.Z, newPos.Y)+(math.pi/2);
	print(vAng);
	setAngle(vAng);
	setAngle(hAng, true);
end

The reference object has been rotated by 90 degrees, hence the ‘newPos’ components being switched around

getAngle is being called every .Stepped with the world position of the red part.

Any help or suggestions would be appreciated.

I have tried changing the “MaxVelocity” property to both 0.05, 2*math.pi, and 5, but with no positive effect to the outcome.

Demonstration:

Make your MaxVelocity very low, like 0.005 is still kind of fast.

While it appears smoother due to it taking longer to move between the angle, there is still a noticeable stop between each movement like before. I presume MaxVelocity is taken in rad/s or rad/frame anyway, so surely having it at 2*math.pi or 5 should instantly move between each angle each frame?

This probably means your numbers are not precise enough.

If you look at the output in the gif then it appears as if the number is changing each update. If it’s a case that the :SetDesiredAngle is flooring the angle to a certain number of decimal places then that could be feasible, but from the print it appears as if the precision is not the issue.

1 Like

I’m going to assume it’s the flooring to certain decimal places, I’ve had that happen in my Motors trying to do stuff like this.

That’s very irritating then. I wanted to avoid welds or manually setting the CFrame. Are there any alternatives you can think of that would work as a decent go-around?

I hate doing anything without Motors for this kind of thing, I don’t think there is any feasible alternative. However, there are HingeConstraints which use actual degrees, so you can add decimal places on top of the degrees. I’ve never used them before though, so your mileage may vary.

1 Like

I’ll give it a shot. Much appreciated.

1 Like