Hello everyone,
I have this bus and I want to use a wheel colliders to move it, so I added a box collider and Rigidbody to the GameObj this box collider it will be responsible for the bus interacting with the outside world like road and other cars
And here I declared to unity that I don’t want the layers with Interior to ignore the layers in exterior layer
I gave the object that carry the box collider a exterior layer and the object that carry the mesh collider a interior layer,
but for some reason the bus fly high when I start the game.
The interior collider is not the problem here, as it has no rigidbody on its own. Does anything inside the exterior collider have its own rigidbody that is set to kinematic? What about the player, does he spawn inside the bus? If a kinematic rigidbody is the child of a non-kinematic rigidbody and overlapping with its collider, this type of behavior will happen.
As you can see in the picture the parent GameObj is the only object that have a rigidbody and it not kinematic.
The player have a character controller, and the player initial position is inside the bus
The player controller works similar to a kinematic rigidbody, at least in this situation, and if he is inside the exterior box collider, this means they interact with each other. As far as Unity is concerned, a box collider is solid and it will try to push out anything inside that is affected by physics, or if the collider itself has a rigidbody, it will try to get away from these objects. However, if the objects are children of the collider itself and have a kinematic rigidbody or a player controller, this is not possible, as the child objects will move together with the parent object, resulting in unintended behavior. You could exclude the player from colliding with the exterior as well, if that works for you.
However, if you want the player to be able to move inside the bus while it drives, you will get a different problem, because your interior mesh collider is not convex, so it will not work with the rigidbody of the parent object. Concave colliders only work with kinematic rigidbodies or objects with no rigidbody at all. You would have to build an approximated collider out of multiple box colliders for this to work, and then not use a single large box collider for the interior, but one for each side.
As you see here I declared to unity that the interior should only collide with the player and the exterior should not collide with the player and the interior.
the result of this is the player do not colliding with both the interior and exterior.
I tired removing the rigidbody from the parent no wired result the player stay in bus and the bus don’t fly or something. but I need the rigidbody because I want to move the bus with the wheel colliders
That is probably because the interior collider is not convex, as non-kinematic rigidbodies only work with convex colliders, and the interior is treated as part of the parent rigidbody’s collider, because it doesn’t have one itself.