Calculating a StaticBody/AnimatableBody's velocity

I have a AnimatableBody that moves along a set path and I want to calculate its’ velocity. I have tried using (GlobalPosition-LastPosition)/delta , however when I apply the resulting velocity to a RigidBody, it does not match the speed of my AnimatableBody. Basically I want to know how Godot calculate the LinearVelocity of RigidBodies to apply the same logic to Static or Animatable bodies. Any help is appreciated.

You can get some extra information of a CollisionObject3D by querying the PhysicsServer3D directly.

For example, to query the linear velocity of a body you can use PhysicsServer3D.body_get_state() like:

extends Node

@onready var animatable_body_3d: AnimatableBody3D = $AnimatableBody3D

func _physics_process(delta: float) -> void:
	var linear_velocity = PhysicsServer3D.body_get_state(animatable_body_3d.get_rid(), PhysicsServer3D.BODY_STATE_LINEAR_VELOCITY)

The same can be done with the PhysicsServer2D for 2D