Carrying objects similar to Source engine

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

I have some RigidBody objects I would like to be able to pick up and carry. I still want them to have physics and not go through walls and stuff, and not feel so stiff like when I just parent them to the player. How should I do this? Rotation doesn’t really matter.

I don’t really know and I’ve never tried that before but I would start experimenting with the following:
get the global coordinates of the camera’s local position+50 in the z axis, let’s call that position “target_position”. get the objects global position. use the get direction_to() function to get a vector that points from the objects global position to the target position. from the object move and slide towards the direction_to value you just go, so something like…

move_and_slide(self.global_transform.origin.direction_to(target_position))

zen3001 | 2019-12-05 19:03

I can’t use move_and_slide, this is all in 3D (Spatial) and it’s a RigidBody…

andersmmg | 2019-12-05 19:50

:bust_in_silhouette: Reply From: andersmmg

I got it working! I figured maybe someone else could use this too if they want to do it this way.
I used a PinJoint on the Player and I have it dynamically set the node_b to an object when I pick it up, as well as disabling sleeping (otherwise I have to collide with it to wake it up every time) and changing the position to the center of the joint to make sure it’s not just swinging around. It works surprisingly well and collisions with other objects work well.