[SOLVED] The lerp() function pushes RigidBody3D through CollisionShape3D



#You should read the post so you would understand what it is all about but long story short
if you want to use interpolation with RigidBodies to carry an item for example, you can use the set_linear_velocity()

item.set_linear_velocity((B - item.global_position) * t)

B is the position you are trying to move your item to.
I guess set_linear_velocity works kinda like interpolation but for RigidBodies()

I have a game where character can walk and carry items.
For picking up an item I made a point, then I am using lerp() to interpolate the item’s position to the point’s position.

Everything works fine except now I can push rigid body through collisions( CollisionShape3D). It looks like the Rigidbody3D slows down for a little bit and then flips through a collision when I am moving my object for example into a wall with a CollisionShape3D, after i let it go it can simply stay there, inside of a collision.

1.An example of five RigidBodies affected by gravity standing perfectly still

2.An An example of the same five RigidBodies affected by my carry_item() function clipping through each other and the wall

!Warning! I did check all the collision layers and masks, it is not the problem. It seems like the collisions still matter but the lerp function with some effort still can push the RigidBodies if the carry_power(the variable bellow in the script) is enough.

When i pick up an object i am setting the gravity scale to 0 so this way the gravity is not going to become stronger and eventually smash my object into the floor. After I set gravity_scale to 1 back.

I will extract from the script only the part about carrying a RigidBody3D so you dont need to look for it.

(Creating variables)

#item carrying

var Items := 
var carry_power := 0.2
@onready var holding_position = $“Head/Camera3D/Holding position”

(The part where i use the created list and function bellow in a physics process)

#carrying items
for item in Items:
if item != null and Input.is_action_pressed(“Carry”):
item.gravity_scale = 0
	carry_item(item, carry_power)
	item.gravity_scale = 1

(The part where i make an array with an object and create a carrying lerp() function)

func carry_item(item, _t):
item.global_position = lerp(item.global_position, holding_position.global_position, _t)

func _on_area_3d_body_entered(body):

func _on_area_3d_body_exited(body):
body.gravity_scale = 1

I am a newbie in Godot and will be very grateful if somebody helps!
English is my second language so I might have made some mistakes here still, i tried to make it clear about the issue if somebody desires to help :smiley:

RigidBodies should not be moved by setting position directly, they need forces to be applied to be have correctly. You may need to override _integrate_forces for this effect with a rigid body to work