How do I make good guy attacks only hit bad guys and vice versa?

Posted by tieTYT on Game Development See other posts from Game Development or by tieTYT
Published on 2013-06-20T22:35:21Z Indexed on 2013/06/26 10:29 UTC
Read the original article Hit count: 633

My game has many different type of good guys and many different type of bad guys. They will all be firing projectiles at each other but I don't want any accidental collateral damage to occur for either alignment. So bad guys should not be able to hit/damage other bad guys and good guys should not be able to hit/damage other good guys.

The way I'm thinking of solving this is by making it so that the Unit instance (this is javascript, btw), has an alignment property that can be either good or bad. And I'll only let collision happen if the

class Attack

    boolean didAttackCollideWithTarget(target)
        return attack.source.alignment != target.alignment and collisionDetected(attack.source, target)

This is pseudo-code, of course.

But I'm asking this question because I get the sense that there might be a much more elegant way to design this besides adding yet another property to my Unit class.

© Game Development or respective owner

Related posts about collision-detection

Related posts about architecture