How do i make a Motor6D smoothly decelerate before reaching its DesiredAngle?

So i wanted to make a motor6d stop smoothly (or in other words decelerate) before reaching its desiredAngle, but i cant seem to find the right methods to do so

I have made my own script which is this

local function tweenSpeed(instance, t, eStyl, eDir, propval)
	game:GetService("TweenService"):Create(
		instance,
		TweenInfo.new(
			t,
			eStyl,
			eDir
		),
		propval
	):Play()
end

local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function()
	if script.Parent.CurrentAngle +  1 == script.Parent.DesiredAngle then
		tweenSpeed(script.Parent, 1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, {MaxVelocity = 0})
		print("yes")
	end
end)

I have tested it too, but it seems like the part where it calculates if the currentAngle + 1 = desiredAngle does not work for some reason. (the “print(yes)” is just to check if it works, but it does not)

I have also tried asking chatgpt to make a script to achieve the deceleration, but it seems like it’s also as confused as i am. please let me know if there are mistakes in my code (because idk if theres anything wrong, no errors popped up), and if this script turns out to just not work entirely, i would very appreciate if someone could make a script that does. thanks!

It’s probably because CurrentAngle is going to be a small decimal different so if the CurrentAngle is 88.9999999 or 89.0000001 and your DesiredAngle is 90 then it’ll never equal exactly.
Try using <= instead of == and make it check more than just the last 1 degree of movement. 1 degree of movement isn’t really much to give you a deceleration so try 3 or 5 degrees.

i just tried it, and it decelerated. but where it stopped isnt at the desired angle which is what i want it to be, is there any way to make this happen? also if i were to use <= it would be executing the tween even if the currentAngle+1 isnt exactly equal to the desiredAngle, so it would execute even before reaching the threshold

1 Like

The problem with decreasing the MaxVelocity of a Motor6D or Motor is that once it gets below about .01 it doesn’t stop at the same point. You may want to check to see what the lowest value you can rotate it by and still get to the same point every time, then use this as your lowest speed at the end of the tween.
Changing the speed won’t change the DesiredAngle. All this will do is change where the speed starts to slow down.
The other option would to be to math.round the value of the CurrentAngle to something like tenths of a degree if you want it more accurate for where it signals the angle change. Instead of going by 1 degree units you could do the if check by .1 degree units.