I’ve noticed that in Urho3D, rigidbodies do not account for colliders in child nodes.
A rigidbody component will notice multiple collisionshapes on the same node, and create a btCompoundShape including each. However, if I have an object with a matching collisionshape and parent it to a node containing a rigidbody, the child’s collisionShape is completely ignored.
This might be intended behavior, but I feel like it is unintuitive at least for me, coming from Unity where a rigidbody will make use of every collider in the hierarchy. I’ve tried to change the code for this, but I’ve had no luck.
In Rigidbody.cpp:
PODVector<CollisionShape*> shapes;
//CHANGED CODE: recursive search for every CollisionShape in children nodes
node_->GetComponents<CollisionShape>(shapes, true);
for (PODVector<CollisionShape*>::Iterator i = shapes.Begin(); i != shapes.End(); ++i)
(*i)->NotifyRigidBody(false);
In CollisionShape.cpp:
btCompoundShape* CollisionShape::GetParentCompoundShape()
{
if (!rigidBody_)
rigidBody_ = GetComponent<RigidBody>();
//CHANGED CODE: if there is not a rigidbody in the same node, look for a rigidbody at the top of the hierarchy
if (!rigidBody_)
{
rigidBody_ = GetNode()->GetSuperParent()->GetComponent<RigidBody>();
//GetSuperParent() returns the highest node in the hierarchy that is not the scene itself
}
return rigidBody_ ? rigidBody_->GetCompoundShape() : 0;
}
What I’ve been doing as a workaround is that when I parent a node at runtime, I create a copy of the CollisionShape component and attach it to the parent node with the rigidbody. However, I need to keep track of which CollisionShape copies correspond to which children, for example so that I can remove CollisionShapes when removing the child node. Would love for some guidance on this. Thanks!