MyGame.Unit.collideWith C# (CSharp) Method

collideWith() public method

public collideWith ( Unit otherUnit ) : bool
otherUnit Unit
return bool
        public bool collideWith(Unit otherUnit)
        {
            //return (BoundingSphere.Contains(otherUnit.BoundingSphere) != ContainmentType.Disjoint);
            return (BoundingBox.Contains(otherUnit.BoundingBox) != ContainmentType.Disjoint);
        }

Usage Example

        public bool checkCollisionWithBullet(Unit unit)
        {
            // If shot is still in play, check for collisions
            for (int j = 0; j < monsters.Count; ++j)
            {
                if (monsters[j].unit.alive && unit.collideWith(monsters[j].unit))
                {
                    monsters[j].health -= myGame.difficultyConstants.MONSTER_HEALTH_PER_BULLET;
                    hpBillBoardSystem.setTexture(j);

                    if (monsters[j].health <= 0)
                    {
                        monsters[j].Die();
                        monsters[j].unit.alive = false;
                        myGame.mediator.fireEvent(MyEvent.M_DIE);
                    }
                    else
                    {
                        monsters[j].TakeDamage();
                        ((MonsterUnit)monsters[j].unit).moving = true;
                    }
                    return true;
                }
            }
            return false;
        }
All Usage Examples Of MyGame.Unit::collideWith