I’m currently working on adding drones to my game with attached Rigidbody2D. I’m using rigidbody2D.AddTorque to turn them, and at times these drones will “pick up” other objects such as crates by making them children. Everything has been working perfectly fine for a few weeks now, but now suddenly there is a significant slow down in the turn speed if a drone has a crate attached as a child IF the crate has its Box Collider 2D activated. As soon as I deactivate the Box Collider 2D on the crate the drone starts turning at the correct speed again.
I haven’t touched any code related to the drones or crates in weeks and now that I’ve restarted Unity this is happening. Is there something I’m missing?
Instead of making it a child, you should attach a HingeJoint to the drone. Then dynamically at runtime change the value of what the other connected body should be (whatever object you’re wanting to pick up). And make sure you have Collide Connected set to false. Then later if you want the drone to let go of the object, just set the value of the connected body on the HingeJoint to null.
This is probably a bug that was fixed. Essentially the rotational inertia was being calculated based upon the 2D colliders on the rigid-body. Box2D auto-calculates both mass and rotational inertia this way (mass is the area * density of the collider). The current default for Unity is to suppress this and allow explicit selection of mass.
I have changed this so that rotational inertia isn’t affected (auto-calculated) based upon the attached 2D colliders.
In the future, I’m looking at allowing both mass and rotational inertia to be auto-calculated based upon an option on the 2D rigid-body.
Very much looking forward to this fix; I have experienced this when adding a circle collider 2D to a rigidbody2D, throwing the objects Rigidbody2D.angularVelocity well outside expected values.