How do I get the velocity of an anchored part?

BasePart.AssemblyLinearVelocity and the now deprecated BasePart.Velocity only works on unanchored parts.

However, I have an anchored part that I move by setting the CFrame of it.

I need to find the velocity of that part. My current solution is to calculate it manually by finding the change in position over time.

Are there any built-in methods/properties for finding the velocity of anchored parts? It would be much easier for the future.

2 Likes

From what I understand, what you’re doing here is updating the CFrame every __ which does the same job as moving it with something like a vectorForce. Technically, this isn’t velocity and is just a part which you’re constantly updating. This means there’s no function to calculate its velocity.

You could, however, to make it a simpler process for you, turn your solution into a function which you can then call at your leisure.

1 Like

If you are moving a part via CFrame then you should probably already have the formula for the velocity like so:

local RunService = game:GetService("RunService")
 
local RATE_PER_SECOND = 2
 local part = Instance.new("Part")
part .Anchored = true
part .Parent = workspace
RunService.Heartbeat:Connect(function(step)
	local increment = RATE_PER_SECOND * step
part*= CFrame.new(0,increment,0) -- move the part up 2 studs per second
--velocity is (0,Rate_Per_Second,0)
end)

Otherwise if it’s more complicated you can just measure the rate of change of displacement which is velocity

local RunService = game:GetService("RunService")
 
local RATE_PER_SECOND = 2
 local part = Instance.new("Part")
part .Anchored = true
part .Parent = workspace
local previousPartPosition = part.Position
RunService.Heartbeat:Connect(function(dt)
local displacement = part.Position - previousPartPosition 
local velocity = displacement/dt -- your part velocity

previousPartPosition  = part.Position
end)
3 Likes

Thanks for taking the time to type this solution! Hopefully, there will be a built-in solution for this in the future. In the meantime, I’ll do this and make it into a function like what Benified4Life said.