Tween part to move at constant speed regardless of distance

Hello, I don’t know how to tween a part at a constant speed no matter the position of the end goal.
Here is an example


The elevator goes up really fast when it has to go up 2000 studs and it goes really slow when it has to go up 50 studs.

I want this to be a constant rate, so no matter if it is going to go 2000 studs in the air or 10 it will move at the same speed, how would I do this?

I have found no answers to this on dev forum.

Script (probably not necessary)
-- this gets triggered a lot of times per second, it detects when the player moves the lever
		logisticPort.Powered.Changed:Connect(function(powered)
			
			local MoveBy = logisticPort.MoveBy.Value -- cframe value
			
			-- the important part
			TweenService:Create(Main.Target,TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{CFrame = CFrame.new(MoveBy.Position.X * powered, MoveBy.Position.Y * powered, MoveBy.Position.Z * powered)}):Play()
			
		end)

P.S. The elevator is using a rigidconstraint

This is because you made it so that time is constant, v = s/t so if you increase the displacement then velocity will also increase. To keep velocity constant, you need to define a constant for velocity,

t = s/v

How would I do that? I did try something like distance/constant or something but that didn’t seem to work.

If distance is Speed * Time then time is distance divided by speed. Try to use this equation

local t = MoveBy / 50
TweenService:Create(Main.Target,TweenInfo.new(t,Enu...

it is indeed distance/constant, the constant here represents the rate at which the position changes.

I can’t divide CFrame by number, would I instead do

local t = MoveBy / CFrame.new(50,50,50)

t = (Main.Target.Position - MoveBy.Position).Magnitude / 50

2 Likes

You need to get the distance from the start point to the end. If it only moves up or down then it will be easier.

local distance = MoveBy.Z - CFrame.Z
local t = distance / 50

...


It seems to work fine going up but it is really slow going down.

edit:
image
Target.CFrame can be any of the points on the red line, this ‘elevator’ also works on multiple axes, so it can go X,Y,Z.

edit 2:
MoveBy.Value (a cframe) is the value inputted by the player, like 0,1000,0 or 0,500,0
or the final distance that the elevator will move by.

1 Like

Turns out that this actually worked! I just mistyped it and put in the wrong values

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.