Replacing moving KinematicBody with moving RigidBody gives slight pause in movement

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By peterpop

Hi

First some code:

var rigid_body_node = kinematic_body_node.rigid_node_object
var org_node_loc = kinematic_body_node.global_transform
rigid_body_node.global_transform = org_pcl_loc
rigid_body_node.linear_velocity = Vector3.RIGHT * 2.1
node_on_PathFollow.remove_child(kinematic_body_node)
main_scene.add_child(rigid_body_node)

The node on the PathFollow has an animation that tilts it. This code is run in the animation_finished signal handler. What I am doing is replacing a kinematic body with a rigid body when the animation is finished. Before this time i need the object to be kinematic so I can control it when it moves along with node_on_PathFollow. After this time i need it to be rigid so the physics engine can take control.

It is practically working. The kinematic node is replaced with the rigid node (which is held as a var inside the kinematic node). The new rigid node is also sliding down the tilted node pretty much as expected. I still need to fiddle with the numbers.

But as you can see I try to apply some velocity to it just before I put it in the scene. This is to replicate the speed the kinematic node has as it’s moving along the PathFollow. The 2.1 is just a rough estimate. From its own perspective, the kinematic node is not moving at all. But the node it’s attached to is. But not with any kind of force. I use the unit_offset on the PathFollow (is there even any other way…).
So… (I would like to have shown a video, but I don’t have the capability) at the exact moment I put the rigid body node into the scene it is supposed to move along its right axis (Vector3.RIGHT * 2.1), but it looks like there is just a single frame of, well, it looks like it’s not moving for the slightest of time. Maybe one frame. Then it moves with the velocity given. It gives a very noticeable stutter. Naturally I want the animation to look seamless going from one node to the other.

I don’t know the first thing about the physics engine, so maybe someone has any idea what could be causing this small stutter, and maybe how to mitigate it.