How can I make a tween move at the same speed all the time?

Lol now that I can finally access studio can finally fix this problem I’m trying to make this payload push thing where if you’re in the circle it tweens the payload and if you’re not it stops and I seem to have gotten it working the only issue is I can’t seem to get the speed consistent. Whenever you walk in and out a bunch of times the tween seems to get slower and then goes back to normal when it reaches the next point? How can I always keep it moving at the same speed?

Here’s my coding

--| Modules |--
local Zone = require(SSS:WaitForChild("Zone"))

--| Constants |--
local PAYLOAD_MODEL = workspace:WaitForChild("Payload")
local PAYLOAD_RADIUS = PAYLOAD_MODEL.Model.Radius
local PAYLOAD_ZONE = Zone.new(PAYLOAD_RADIUS)

--| Variables |--
local Moving = false
local Deb = true
local Map = workspace.TestMap1

--| Payload Settings |--
local Speed = 20
local RotationSpeed = 1

--[[note
Current Issues:
- Gets slower each time tween plays
- Need to keep the player moving with the payload if standing on it instead of just sliding off
]]

local RachedNodes = {}
local CurrentNode = Map.Node
function MovePayload()
	local ReachEnd = false
	while Moving and ReachEnd == false do
		warn("Moving to "..CurrentNode.Name)
		local MovementInfo = TweenInfo.new(
			Speed,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out
		)
		MovementTween = TS:Create(PAYLOAD_MODEL.PrimaryPart,MovementInfo,{CFrame = CFrame.new(CurrentNode.CFrame.X,PAYLOAD_MODEL["Part"].CFrame.Y,CurrentNode.CFrame.Z)})
		MovementTween:Play()
		MovementTween.Completed:Wait()
		
		if Moving then
			local NextNode = CurrentNode:GetChildren()
			if #NextNode > 0 then
				CurrentNode = NextNode[1]
			else
				warn("Reached End")
				ReachEnd = true
			end
		end
	end
end

PAYLOAD_ZONE.playerEntered:Connect(function(Player)
	if #PAYLOAD_ZONE:getPlayers() == 1 then
		warn("Moving Payload")
		Moving = true
		MovePayload()
	end
end)

PAYLOAD_ZONE.playerExited:Connect(function(Player)
	if #PAYLOAD_ZONE:getPlayers() == 0 then
		warn("Stopping Payload")
		Moving = false
		MovementTween:Cancel()
	end
end)

1 Like

Try the Linear tween style.

EDIT: I see you are using that already, I didn’t read the code fully. I’ll come up with some fix in the meantime though.

EDIT 2: I can’t replicate that at all, whenever I try to use the Linear tween style, it does exactly what I expect. This might be a bug, if so then report it.

It isn’t a bug. It’s because the distance between point A and point B is different when he tweens it to the next spot. It requires math and I’d say that tweening in this scenario isn’t a good option.

Now again, to solve something like this, you can change the distance to match the same distance as the previous point however you would have to :Cancel() the tween when it reaches the point.

You could also change the speed itself that the tween takes to reach the destination.

1 Like

Calculate the amount of distance between the nodes, then determine how fast you want to go based off the distance.
For example, if points A and B are 10 studs apart and it takes one second to get there, then your desired speed is going to be 10 studs/second. If you want to move at the same pace from point B to C, and the distance is 15 studs apart, then you’ll have to work out how long it will take. We know the original studs/second is 10/1. We know the studs (15), and we have to work out the seconds. This is just a ratio that can be represented by 10/1 = 15/x. To solve, we can do 1*15 = 10x then simplify further to get 15=10x. More simplification leads to 1.5=x. Now we know that it will take 1.5 seconds to move at the same pace between points B and C. How to script that? Thats for you to work out.

4 Likes

create a tween goal with everythig set in it, if u want to have a constant velocity then set the tween time to [distance]/[constant value of velocity]