Exemple #1
0
        private void collideBullet(Bullet bullet, GameObject o2)
        {
            Vector3 originalPosition = bullet.lastPosition.pos();
            Vector3 newPosition = bullet.position.pos();
            Vector3 forwardVector = bullet.position.pos() - bullet.lastPosition.pos();
            forwardVector.Normalize();
            Ray forwardRay = new Ray(bullet.lastPosition.pos(), forwardVector);
            BoundingSphere sphere = new BoundingSphere(o2.position.pos(), o2.size);
            float? intersectDistance = sphere.Intersects(forwardRay);

            if (intersectDistance != null)
            {
                if ((float)intersectDistance < forwardVector.Length())
                {
                    gameScene.ignore(bullet, GO_TYPE.BULLET);
                    o2.takeDamage(bullet.damage);
                    bullet.OnDeath();
                }
            }
        }