When my Character interacts with a RigidBody3d, my speed is increasing exponentially and I'm not sure how to prevent that

Godot Version

4.2.1.stable

Question

Hello! I am currently working on a 3D puzzle platformer (it will be a sidescroller, but I am looking to keep the art style of a 3D game, as everything in the background will be cardboard cutouts and other “arts and crafts”-esque objects.

While I have figured out movement and applying a force to the rigid body my character is colliding with, I am having trouble with the character rabidly accelerating towards infinity, along with the rigid body it is colliding with.

Additionally, the object will simply not move occasionally, and it is seemingly randmo when I can push the object and when I cannot.

I would like to avoid using impulses, as was my original plan, because it is jittery and I am planning on slowly pushing these objects throughout the map instead of simply applying one-time forces.

CODE:

extends CharacterBody3D
class_name CharacterBody


@export var SPEED = 2
@export var JUMP_VELOCITY =4
@export var PUSH_FORCE = 25
@export_range(0.0, 1.0) var FRICTION = 0.1
@export_range(0.0, 1.0) var ACCELERATION = 0.25

#get gravity from project settings
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")


func _physics_process(delta):
	
	#falling
	velocity.y -= gravity * delta
	
	#movement
	var dir = Input.get_axis("input_left", "input_right")
	if dir != 0:
		velocity.x = lerp(velocity.x, dir * SPEED, ACCELERATION)
	else:
		velocity.x = lerp(velocity.x, 0.0, FRICTION)
		
	#jumping
	if Input.is_action_just_pressed("input_jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		
	move_and_slide()
	for i in get_slide_collision_count():
		var c = get_slide_collision(i)
		if c.get_collider() is RigidBody3D:
			c.get_collider().apply_central_force(-c.get_normal() * PUSH_FORCE)

Here’s a small tutorial on how to setup CharacterBody3D and RigidBody3D interactions Character to Rigid Body Interaction :: Godot 4 Recipes (it’s for 2D but the same applies in 3D)

Thank you!

I did actually see this tutorial, but the only issue I’m having with impulses are that they are:

A) causing jittery movement with the rigid body as mentioned in my post, and

B) are causing the item to begin to glitch into the ground depending on the speed at which the player approaches the object. Is there any way to use the force, as the godot docs mentioned that apply impulse is best used for one-time interactions (which has been my experience with impulses).

Applying forces seems to be what I am looking for, but if there’s no way to use those instead and a way to resolve these issues with impulses then I would be open to that as well!