Preventing clipping of held objects with other objects

Godot Version

4.4.1.stable

This issue’s driving me insane aaaaa
Ok so I have a game which heavily relies on picking up objects and placing them.

The objects are rigidbodies that disable some properties while being held to prevent oddities happening. While held they form a stack above the player that can get taller if one falls onto the stack or if the player keeps adding more objects by placing it down and picking them up with the stack.

The problem I’m facing is that these stacks of objects can be walked into falling objects causing them to clip into eachother as the way they’re moved is through directly changing global_position (which is a no-go for physics movement).

I’ve tried a few solutions to the problem such as:

  • Giving the player an extra collider that resizes based on how many objects you’ve picked up (which caused out of bounds clipping and sudden movements)

  • Changing the object movement code to instead use linear velocity which does result in collisions but also causes the stack to be pushed apart if you move into falling objects and also offsets the player from the stack (both big no-nos)

Everything I’ve tried, even when it allows for collisions, seems to have some sort of drawback I’m not sure how to work around. Would appreciate some thoughts on how to approach the physics here!

Rigidbody2D/3D are intended to be used when you want something to be interacted with through outside force. So they’re good for things like sliding block puzzles and grenades. If you want something that only moves if you code it to move, you want to use a StaticBody2D/3D.

StaticBody3D probably is the best thing to use for what I’m doing I’m just worried about programming all the forces and such lol.

Either way, in the end I figured out a workaround to my problem where I just used raycasts to detect if there was a not held object in the way and prevented player movement in that direction if it found one since that was the main problem. Not the perfect solution but it works well enough!

1 Like