Finding the "Velocity" of a tween?

Hi,
I’m trying to make a tween that tweens the player’s RootPart, and launches them forward a bit after it ends. I want it to match the speed and direction that the tween sends you. The tween’s speed always changes, since it’s set as a variable, so doing it manually isn’t an option, unfortunately.
I tried having Roblox print the player’s velocity in the middle of the tween, but their velocity doesn’t actually change due to the tween at all. Is there any other way I can calculate how fast, and what direction, the player is moving during the tween?
Here is my code:

local player = game.Players.LocalPlayer
local rootpart = player.Character:WaitForChild("HumanoidRootPart")

rootpart.CharacterHitBox.Touched:connect(function(hit)
if hit.Name == "spring" then
	local destination = hit.Parent.MoveThis.Position
	local distance = (rootpart.Position - destination).Magnitude
	local secs = distance / 60
	local tweenInfo = TweenInfo.new(secs, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
	local tween = TweenService:Create(rootpart, tweenInfo, {CFrame = hit.Parent.MoveThis.CFrame})
	tween:Play()
	wait(secs)
	rootpart.Velocity = (???)
end
end)

Its because you set the CFrame, and changing the CFrame doesn’t change the velocity. In order to get the velocity, you have to use BodyMovers since they use roblox physics.
The velocity property only changes if the part is unanchored.

Is there a way to replicate velocity? Like, calculate how many studs the tween is sending them per 0.05 seconds or something?

Mess with the numbers, me personally I try my hardest to avoid math so I just do random numbers.

You do notice that you have set the velocity to 60 right? when you calculate the secs you do distance/velocity, so the velocity you have right now is fixed and not variable.

You can probably use simple physics equations to roughly estimate the velocity. Since you’re easing style is linear, you can just velocity = distance / time

local distance = (origin - destination).Magnitude
local time = TweenInfo.Time
local velocity = distance / time -- rough estimate of velocity
1 Like

Thank you. Is there a way to convert that velocity into a Vector3? That’s the part I’m most stuck on.

Just define distance as destination - origin

3 Likes

I didn’t realize you could divide Vector3s with normal numbers. Whoops! Thank you, though!