Hi, AssemblyLinearVelocity works only for physics based objects and I need to calculate velocity for a part that is moving by constantly updating CFrames.
I also need to know which direction the part is going.
Any help is greatly appreciated.
Hi, AssemblyLinearVelocity works only for physics based objects and I need to calculate velocity for a part that is moving by constantly updating CFrames.
I also need to know which direction the part is going.
Any help is greatly appreciated.
Hey, velocity is calculated based on the previous position and the current position of the object in time t. Putting this together you can just do:
local velocity = (PreviousPosition - CurrentPosition) / DeltaTime
PreviousPosition = CurrentPosition
You can achieve this by measuring the positional delta (rate of change) of the object.
Sample code:
local velocity = Vector3.zero
local lastPosition = object.Position
RunService.RenderStepped:Connect(function(dt)
local delta = object.Position - lastPosition
velocity = delta / dt
lastPosition = object.Position
end)
Your example seems to be working, however I am noticing a slight issue.

For some reason it always skips a frame.
Well as I said, it’s just an example to help you get a rough idea on how to calculate velocity. It’s by no means an ideal implementation.
use PreSimulation to modify velocity so it is ready for the physics to use
I am not modifying velocity im just trying to calculate it. Physics also do not apply here, as im updating position by CFrames.