Box colliders, rigidbody -> Player and picked up cradle

Hi everyone,

in my game the character can pick up a cradle.

To do this, I have attached 2 box colliders to my cradle: One to prevent that the character walks through the cradle and one (slightly bigger) to work as a trigger (to detect if the player stands aside the box).

When the character picks up the cradle, I simply attach it to the player character.

My first approach was to simply attach the cradle to the player and that’s it. The problem is that the cradle’s box collider (the one preventing the player to walk through the cradle) intersects with the rigidbody of the player character and thus prevents the player character to move.

My second approach was to switch the box collider into a trigger, once the player has picked it up. Now, the player moves as expected, but unfortunately, the box disappears into a wall when the player character stands aside the wall.

My third approach was to disable the collision detection between the rigidbody.collider and the box collider (Physics.IgnoreCollision(rigidbody.collider, boxCollider, true);). This seems to work since the player is able to move. But the box still disappears in the wall. I was hoping that the active box collider then would disable the player to walk close enough to the wall for the box to disappear in it.

My questions:

  1. Is this “double box collider” approach “the usual way” to handle this “player approaches object he wants to pick up” issue?

  2. How can I prevent my player to do any collisions with the box but the box still prevents the player to approach the wall?

Thanks for your help.

Hm… Does the cradle have a rigidbody on it?

No, the cradle doesn’t have any rigidbody… I’ve attached one to see if it changes anything, but it doesn’t work.

The player character is moved by CharacterController.Move() if that changes anything. The RigidBody on the player character is set to Kinematic.

Hm, perhaps the kinematic rigidbody is the problem. Since you’re using a character controller, any rigidbody at all would be redundant. A kinematic one could cause problems.

Nope… I removed the rigidbody part of my player character. Still, when the boxes’ collision box is not set as a trigger, the player character cannot move.

sigh

Hasn’t anyone the same problems as me? I mean, it should not be unusual to attach an object to another one and the “combined” collision boxes are handled…

How do you attach it to the player character? You make the character the parent of this object?

Yes… I simply attach the cradle like this:

_pickedUpObject.parent = transform;

transform being my character’s tranform.

The object have two GameObjects, one with the trigger and other with the collider?

Yes :slight_smile: So basically I don’t see why this fails.

I’ve already lost more time with the physics engine than I’d like to admit (bouncing boxes on moving platforms, this character controller ↔ attached object problem)… I’ve decided to try a fresh approach which in the same time, gives me more flexibility in the character movement.

Thanks for helping