I have a simple "third person cam" space shooter using a GameObject which contains a valid 3D ship mesh, and various planes used for effects (engine glow and crosshair).
I would like the position of this object to be defined by an invisible rigidbody sphere. However, when I place the rigidbody sphere at the top of the GameObject, I get compile errors:
Apparently this is caused by the auto-tensor-assignment process, which trips up on zero mass meshes (ie. the planes). I don't want these hackily put in seperate game objects and positioned each frame. Is there any way I can get this to behave? I'm sure the Tutorial has rigidbody objects containing sprites but I can't seem to figure out what part I'm doing differently. I tried adding a line on Awake() to set up a default tensor manually, as such:
But that didn't fix it either. Anyone got any suggestions?
This error most commonly arises from placing a Rigidbody on a Plane, so you need to check whether the GameObject in question has a Mesh Collider component which uses "plane" as its mesh. This is because the plane mesh has no depth, and therefore the rigidbody has no mass. You can solve this by using a very thin box (if you really want something which behaves physically like a thin plane), although from the rest of your description it sounds like you're after something else.
Just to clarify - there's no such thing as a "rigidbody sphere" - these are two separate components. The Rigidbody component does not describe the physical shape of the object. The Rigidbody component takes is physical form from the collider component attached to the same gameobject - or, in the case of compound colliders - the combination of colliders attached to each of the child gameobjects which may be parented to it.
So, for a Rigidbody which collides using a spherical shape, you need to add the Rigidbody component, plus a Sphere Collider Component to that gameobject, or a child of that gameobject.
It's entirely possible to display a sprite that corresponds to such a GameObject's position. If you're using the spritemanager (from the wiki), it's simply a case of using the Linked Sprite Manager, and adding a sprite which references the gameObject as the 'client' parameter.
If the above doesn't help, please provide a bit more information about the arrangement of the gameobject hierarchy which is causing the errors!
answered Nov 17 '09 at 12:40 PM
Do your child game objects have colliders attached? A game object that has children with individual colliders will collectively act as a compound collider (this is described somewhere in the Unity Manual in the Physics section - it's a technique to create collision shapes more complex than a sphere or cube), so if you have zero-volume plane/mesh colliders and a parent rigidbody, that might account for the warning. So I suggest you remove any colliders you really don't want or selectively replace them, e.g. replace a mesh collider with a box collider with non-zero width/height/depth. Or rearrange your objects is the children don't really need to be children.
If you still want to set the inertia tensor explicitly, you made the right call - here's another example setting it for a cylinder shape (extracted from some game physics book). But this is more appropriate for a refinement phase after getting the physics to basically work right and error-free.
answered Nov 17 '09 at 08:09 PM
Okay, couldn't see the forest for all the trees! After re-reading your answers, I re-checked my hierarchy and realised I was so busy looking for colliders on the mesh of the ship and its components that might affect the tensor, I forgot to check for colliders on the actual planes of the sprites! Starting their life as unity GameObject meshes, they had colliders added by default of course. Thanks so much for your help, I am now a lot more happy/clear with how these physics entities go together =)
answered Nov 19 '09 at 01:03 AM