- Home /
Compute inertia tensor based only on colliders in same layer as parent?
Hi, sorry about the confusing title, I really don't know what to call this question...
Ok, so, I'm making an airship. It's a rigidbody with gravity disabled. The parent game object has the rigidbody component attached as well as a sphere collider. I placed and scaled the sphere collider based on how I wanted the airship to behave, basically, I made it quite big and centred it around where I wanted the centre of mass to be. I made it big so that the airship would have quite a high... I think it's called moment of inertia or something? Actually I don't think it is... I'm doing a-level physics and further maths, but I haven't covered this yet, I think I will next year. I know that there's angular momentum as well as momentum in a direction, and that the formula for it is going to be something like rotation speed mass some measure of how spread out the mass is.
Well anyway, I stuck this sphere collider so the parent, but I also have a load of colliders on the ship for the player to interact with - it's first person, you can walk around the ship (like in guns of icarus). So, I didn't want the player to interact with the big sphere collider, so I did some stuff with layers, so that the parent is in a layer called "airship", all the child colliders are in the default layer. I set it up with the collision matrix thing so that they don't interact with each other. Oh, and the player's in the default layer too.
Anyway, I have some child colliders which aren't closed shapes, for example, the floor of the airship. It's just like a flat thing. Now, originally, everything worked fine. The airship behaved based on the big sphere collider, the player could walk around on the airship floor. But then, I built the game for windows for the first time. I think something strange happened then, but now when I press play, the airship rigidbody's inertia tensor thing and centre of mass are all messed up. Since the floor doesn't have a volume, it gets all confused and just sets the centre of mass to 0,0,0 and the inertia tensor to (i have no idea how these work) something that means the mass is all really bundled up in the middle. Basically, when I try to turn, the ship spins super fast. It gives me this error:
Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually!
It's fairly clear that this problem is coming up because when unity tried to compute the mesh inertia tensor, it's looking at the colliders of the airship gameobject's children. I don't want it to, and it didn't used to - the airship gameobject itself has no mesh collider or anything. It's only components are rigidbody, sphere collider, and a script i use to control it. What I want it to do, and presume that it used to do is to calculate the inertia tensor taking into account the collision matrix. If it did that, it's see that the child colliders shouldn't interact with the airship rigidbody, and everything'd be fine.
I did some tests - I tried deactivating the non-closed mesh colliders, and suddenly it all worked fine. Well, except that the played just falls through the floor... but yeah, this proves that that's the source of the problem. I would just replace them all with box colliders and stuff, but the floor has like a ramped part, and the edge is a weird shape, and stuff like that, so a box wouldn't fit.
Wow... this is really long... sorry about that
Thats basically it. I've looked in the physics project settings and there doesn't seem to be any settings relative to this. I have tried just setting the inertia tensor manually in script, but it just feels like i'm treating symptoms and not actually fixing anything. It still gives me the error message and everything. Also the centre of mass is still messed up...
Well if you read all that, thank you very much, you're a very patient human! But yeah, any help would be greatly appreciated.
Thanks,
James