Tween get slower as the goal approaches

i need someone to help me with an equation for this tween.

i have a needle gui that need to move at a given speed but not slow down as it gets closer to its goal

local speed = 10


local function spin(direct)
		direction = direct
		local Editrection 
		if direct then
			Editrection = Enum.EasingDirection.In
		elseif not direct  then
			Editrection = Enum.EasingDirection.Out
		end
		if direct == "Died" then
			failed()
		end
		
		local distance = (neddle.Rotation - mid:FindFirstChild("point").Rotation)
		print(distance)
		local goal = {Rotation = mid:FindFirstChild("point").Rotation + 10}
		local Info = TweenInfo.new((distance)/speed,Enum.EasingStyle.Linear,Editrection)
		local needle = tweenservice:Create(neddle,Info,goal)
		needle:Play()
		
		--[[if distance >  then
			failed()
		end]]
	end
1 Like

You are using Linear EasingStyle. Can you show a gif/clip of the problem as there is nothing wrong with your tween table.

2 Likes

Easing Styles are used to change the way the tween plays. Some do more than slow down or speed up. Some slow down and speed up at different speeds.

this is the page describing it in more detail

1 Like

its too fast it just jumps to the point. i need a way for it to move at the correct speed based of the given distance

1 Like

speed = distance / time

so if you want a consistent speed for your tween you need to calculate the time using the distance and speed you want. should look like this

local dist
local speed = 10
local tweenTime 

dist = (target.Position - object.Position).Magnitude
tweenTime = dist / speed

then you’d use tweenTime inside of the tweenInfo object.

1 Like

ServerScriptService.Functions:113: attempt to index number with ‘Magnitude’

1 Like

What is your target.Position and object.Position? They should be Vector3s not numbers.

2 Likes

what are you trying to move? and what values are you using?

they arent parts its all 2d and guis

2022-10-23 13-31-43

can you tell me what values you are using to move it

local function spin(direct)
		direction = direct
		local Editrection 
		if direct then
			Editrection = Enum.EasingDirection.In
		elseif not direct  then
			Editrection = Enum.EasingDirection.Out
		end
		if direct == "Died" then
			failed()
		end
		
		local distance = (neddle.Rotation - mid:FindFirstChild("point").Rotation)
		print(distance)
		local tweentime = distance/speed
		print(tweentime)
		local goal = {Rotation = mid:FindFirstChild("point").Rotation + 10}
		local Info = TweenInfo.new(tweentime,Enum.EasingStyle.Linear,Editrection)
		local needle = tweenservice:Create(neddle,Info,goal)
		needle:Play()
		
		--[[if distance >  then
			failed()
		end]]
	end

wait i just wanna know what properties you are using to move. i dont mean i wanna see ur whole code lol

oh im using rotation to move the gui

Are you playing this tween/calling this function repeatedly?

Given its travel is linear and the duration parameter isn’t changing, the only thing that could make it go slower is if the tween plays again from a lesser distance to its target, thus it won’t need to move as fast to reach the goal of this new tween.

ok then you need some different math to calculate the distance. You need to calculate radians and convert to degrees. And the code should look the same just remove the .position parts on both of them as well as the .magnitude at the end.

if your thing is moving too fast then decrease the speed variable.

oh so the way i have this set up is that the goal is the rotation of the point (the yellow dot)
and the tweens purpose is to move it to that goal but the issue I’m having is the time. the tween slows down once it reaches its goal or if the point is closer to the needle it will go slower and the only other option i had for moving it was a while loop witch lags on the phone

how do i get it to not do that so it rotates at the same speed as its set