Holding and Throwing

In a game prototype I’m working on, a player can grab and hold something (say, a box) overhead and then throw it at will. At present, this is accomplished by childing the held object to the holder object, but this comes with a problem: since there is a rigidbody on the held object, its collisions are not reported to the parent game object, and so the holding character is able to carry the held object through solid objects. That is, the box held overhead would phase through a wall rather than prevent the player from going through a doorway.

I want the held object’s colliders to be used by the holding object’s rigidbody, preventing the player from carrying the object places where its collisions normally wouldn’t allow it to go. What is the best way to do this?

The process of picking up the held object is as follows:

  • Set the held object’s rigidbody to kinematic (to disable its physics – necessary otherwise it won’t be carried along with the parent object)
  • Move the held object into position relative to the carrying object
  • Child the held object to the carrying object

Suggestions desired. If there’s a better way of “holding” another object overhead that would allow its collisions to be inherited, I’m all ears.

The only thing I can think to do is delete the held object’s rigidbody, then recreate it when it’s thrown, but this is not only sloppy and discouraged, it also creates a bunch of problems for me. It would be much better if I could just tell the child’s rigidbody to allow collisions to bubble up, somehow.

Have you tried attaching the box to the character with a joint rather than making it kinematic and using parenting?

If that doesn’t get you what you’re looking for, you could always extend the character’s collider (or add one) to incorporate the bounds of the box into that of the character’s Rigidbody.

1 Like