Sniper Collateral Damage?

ok ive been working on my sniper today, and successfully having it in a beta working state(it needs more work) it dawned on me that the raycast im using doesnt carry on through the enemy so to hit another enemy.

if any of you have ever played cod, most of you will have, is there anyway such way to achieve collateral damage?

thanks :)

Just use RaycastAll instead of Raycast to get info about all objects in line of the shot instead of only the first.


Edit: a working example.

I advice Raycast over collision detection of bullets anyway, because if they move fast it may not register. Raycast is a lot more reliable. I'm assuming all players are tagged player here.

var gun : Transform;   //transform of the front of your gun, where you shoot from.
var distance : float   // how far do you want someone to be able to shoot?
var damage : float;
var collateral : float;

function Update () {

    if(*you shoot*) {

        target = Physics.RaycastAll(gun.position, gun.forward, distance)

        if(target[0].collider.gameObject.tag == "Player") {

            target[0].collider.gameObject.GetComponent("*healthScript*").hitPoints -= damage;

        }
        if(target[1].collider.gameObject.tag == "Player") {

            target[1].collider.gameObject.GetComponent("*healthScript*").hitPoints -= collateral;

        }
}

Now you could improve this script to for instance place a bullethole texture on the target[x].point if the target is a wall, etc.

Good luck with it!

Try to set your enemy as isTrigger, then tell it either to destroy the bullet or let the bullet go and only decrease the lifepoints of the enemy. Not sure if this works though, just trying to think with you. :)

You could try an OnTriggerEnter() that makes a raycast out the back of the enemy at the same angle as the one going into him.