In my catapult game the player has to launch a projectile at a castle wall. The wall is made up of several bricks. These bricks are all flush to each other and do not intersect. Currently they have no rigid body attached so launching a test projectile at them would not do anything to move them. The problem comes with attaching a rigid body. Regardless of gravity, if they are not kinematic, they will collide with one another and before the projectile is launched the castle bricks will be thrown around the level. On the other hand, if they are kinematic, this means they can not be affected by the projectile, only by script.
Is there a way to tell them not to detect collisions against objects of a certain tag? Or perhaps to apply a script when the object with projectile tag has collided with them?
Currently my projectile is only fired by the motion of the catapult arm and therefore moves very slowly (increasing the motion speed would simply make the projectile clip through it. No scripts are being used to determine the momentum of the projectile but eventually there will be a calculation.
asked Jan 04 '12 at 11:59 PM
Yes, it's easy enough to stop them from colliding with each other- just put them all on the same layer, and use Layer Based Collision to prevent that layer from colliding with itself.
However, if you do this, your entire castle will collapse as soon as the game begins! The actual problem is because of the way colliders interact with one another. First off, you should have some kind of script which automatically puts all the rigidbodies in the wall to sleep, so that they won't do anything until they are acted on by an outside force (i.e, the boulder). You may also want to increase the Physics settings' solver iteration count (this will make the simulation more stable).
Another thing- you really shouldn't be relying on physics to throw your catapult projectile. A better way to make it realistic (with minimal complicated maths on your part) would be to have the arm connected to the 'cradle' by a hinge joint, make the projectile a kinematic rigidbody that is a child of the cradle and then manually calculate the boulder's velocity one frame before you would have thrown it. Then, unchild it from the catapault, set it to non-kinematic, and manually set its velocity to the correct value! Then, you won't have to worry about the projectile falling through the catapult arm.