How to stop teleporting a rigidbody away when stopping impulse on a rigidbody3d

Godot Version

4.5.1

Question

so i applied an impulse to another rigidbody3d like this with some rotation

var impulse = direction * SLAP_FORCE
impulse.y = UP_FORCE
	
apply_impulse(impulse)

var random_axis = Vector3(randf() - 0.5, randf() - 0.5, randf() - 0.5).normalized()
angular_velocity = random_axis * deg_to_rad(ROTATION_AMOUNT)

and if i watned to stop the impulse so that like it stops the impulse stays in place and makes the rotion upright like 0,0,0 im trying this, it works and makes it upright but for some reason teleports it far away isntead of staying in place:

func _integrate_forces(state):
if recovering:
state.linear_velocity = Vector3.ZEROstate.angular_velocity = Vector3.ZERO
var origin = state.transform.origin
state.transform = Transform3D(Basis.IDENTITY, origin)

it teleports it away i dont know why and its really annoying and ruins the point of my game

could anyone help

did you try debugging the value of origin?

Could it be that the position is changed somewhere else?