Exemple #1
0
            private void onCollision(EntityCollidable sender, Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
            {
                var otherEntity = other as EntityCollidable;

                if (otherEntity != null && FollowPlayer && otherEntity == player.character.CharacterController.Body.CollisionInformation)
                {
                    if (!player.canTakeTextures) // we absorbed textures too fast
                    {
                        FollowPlayer = false;
                        Target       = targetModel.Entity.Position;
                        linearMotor.Settings.Servo.Goal = Target;
                        try
                        {
                            CollisionRules.AddRule(Model.Entity, targetModel.Entity, CollisionRule.NoSolver);
                        }
                        catch { }
                    }
                    else
                    {
                        player.giveTexture(this);
                    }
                }
                else if (otherEntity != null && !FollowPlayer)
                {
                    if (!targetModel.Texture.Wireframe) // we launched textures too fast. turn around and go back to the player.
                    {
                        FollowPlayer = true;
                        try
                        {
                            CollisionRules.AddRule(Model.Entity, player.character.CharacterController.Body, CollisionRule.NoSolver);
                        }
                        catch { }
                        Target = player.character.CharacterController.Body.Position;
                        linearMotor.Settings.Servo.Goal = Target;
                    }
                    else
                    {
                        targetModel.GiveTexture(CarriedTex);
                        player.remove(this);
                    }
                }
            }
        /// <summary>
        /// Collision happened
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="other"></param>
        /// <param name="pair"></param>
        void Events_InitialCollisionDetected(BEPUphysics.Collidables.MobileCollidables.EntityCollidable sender, BEPUphysics.Collidables.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
        {
            IObject send = BepuEntityObject.RecoverObjectFromEntity(sender.Entity);
            IObject obj  = BepuEntityObject.RecoverObjectFromCollidable(other);

            ///Verifica se esta bola ja foi considerada
            ///Consider just the first collision
            if (alreadProcessed.Contains(obj.GetId()))
            {
                return;
            }

            alreadProcessed.Add(obj.GetId());

            ///se o objeto colidido for diferente do cenario
            ///dont consider the island model (triangle meshes in general)
            if (obj.PhysicObject.PhysicObjectTypes != PhysicObjectTypes.TRIANGLEMESHOBJECT)
            {
                shouldDraw = true;

                ///Envia uma mensagem para o canal de comunicacao CUBO
                ///Send a message to the channel
                Message m = new Message(send.GetId(), PrincipalConstants.InvalidId, "cubo", Priority.MEDIUM, -1, SenderType.OBJECT, null, "CHANGECOLOR");
                MessageDeliver.SendMessage(m);

                ///Esta mensagem foi enviada sem Sender (Quem receber a mensagem nao sabera quem enviou)
                ///Envia uma mensagem para o "CUBO QUE VAI MUDAR DE COR" (lembre que o id dele eh 77 !!)
                ///Send a message to the specific  id (first cube)
                m = new Message(PrincipalConstants.InvalidId, 77, null, Priority.MEDIUM, -1, SenderType.OBJECT, null, "CHANGECOLOR");
                MessageDeliver.SendMessage(m);
            }

            objNameTemp = obj.Name;
        }
Exemple #3
0
 private void Events_DetectingInitialCollision(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
 {
     Health--;
     if (other.Tag is IEnemy)
     {
         ((IEnemy)other.Tag).Destroy();
     }
 }
Exemple #4
0
        internal void Events_ContactRemoved(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair, BEPUphysics.CollisionTests.ContactData contact)
        {
            var collision = GenerateCollision(sender, other, pair, contact);

            foreach (var m in this.gameObject.GetComponents <MonoBehaviour>())
            {
                m.OnCollisionExit(collision);
            }
        }
Exemple #5
0
        private Collision GenerateCollision(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair, BEPUphysics.CollisionTests.ContactData contact)
        {
            var otherEntity   = other as BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable;
            var otherCollider = otherEntity.Entity.Tag as Collider;

            var collision = new Collision()
            {
                gameObject = otherCollider.gameObject,
                contacts   = new Collision.ContactPoint[1],
            };

            collision.contacts[0] = new Collision.ContactPoint()
            {
                normal        = contact.Normal,
                point         = contact.Position,
                otherCollider = otherCollider,
                thisCollider  = this.gameObject.GetComponent <Collider>(),
            };
            return(collision);
        }
Exemple #6
0
        private void Events_InitialCollisionDetected(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
        {
            Console.WriteLine(fuelPackID + " FuellPack Collision");
            var    otherEntityInformation = other as EntityCollidable;
            string tag = (string)otherEntityInformation.Entity.Tag;

            // only remove object if comes in contact with the ship
            if (tag.Equals("ship"))
            {
                if (Game.Components.Contains(this))
                {
                    RemoveFromGame();
                }
            }
        }
Exemple #7
0
 private void Events_InitialCollisionDetected(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
 {
     System.Console.WriteLine("bump" + sender.Tag);
 }
Exemple #8
0
        private void Events_InitialCollisionDetected(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
        {
            Console.WriteLine(torpedoID + " Collision");
            var    otherEntityInformation = other as EntityCollidable;
            string tag = (string)otherEntityInformation.Entity.Tag;

            // hitting the ship doesn't remove the torpedo (would interfer with firing logic
            if (!tag.Equals("ship"))
            {
                if (Game.Components.Contains(this))
                {
                    RemoveFromGame();
                }
            }
        }
Exemple #9
0
 /// <summary>
 /// Event to detect and process collision of the spaceship with something and process mission completeness
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="other"></param>
 /// <param name="pair"></param>
 private void Events_InitialCollisionDetected(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
 {
     if (pair.EntityA.Tag.ToString() == "Mothership" || pair.EntityB.Tag.ToString() == "Mothership")
     {
         goalReached = true;
         if (speed > 6)
         {
             goalReachedTooFast = true;
         }
         else
         {
             goalReachedTooFast = false;
         }
     }
 }
Exemple #10
0
        private void Events_InitialCollisionDetected(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
        {
            // issues with motion upon impact with other objects
            Console.WriteLine("Ship Collision");
            var    otherEntityInformation = other as EntityCollidable;
            string tag = (string)otherEntityInformation.Entity.Tag;

            if (tag.Contains("duck"))
            {
                Console.WriteLine("Hit DUCK");
                if (!shieldActive)
                {
                    health            -= duckDamage;
                    generalInfoMessage = "DAMAGE TAKEN";
                }
            }
            if (tag.Equals("turtle"))
            {
                Console.WriteLine("Hit Turtle");
                if (Vector3.Distance(linearVelocity, maxVelocityToWin) <= 2f)

                {
                    conclusionMessage = "You successfully claimed the sacred Turtle!";
                }
                else
                {
                    conclusionMessage = "Your ship was going too fast! Failed to safely aquire the Turtle.";
                }
            }
            if (tag.Contains("fuelPack"))
            {
                float newValue = fuelLevel + fuelPackValue;

                // can't go over 100 fuel
                if (newValue > 100)
                {
                    fuelLevel = 100;
                }
                else
                {
                    fuelLevel = newValue;
                }
                generalInfoMessage = "FUEL PACK AQUIRED ";
            }
            if (tag.Contains("torpedoPack"))
            {
                // TODO - broken
                // AddTorpedo();
                generalInfoMessage = "TORPEDO PACK AQUIRED";
            }
        }
        private void Events_InitialCollisionDetected(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
        {
            Console.WriteLine(duckID + " Duck Collision");
            var    otherEntityInformation = other as EntityCollidable;
            string tag = (string)otherEntityInformation.Entity.Tag;

            // don't remove if it hits any of the packs
            if (!tag.Contains("fuelPack") && !tag.Contains("torpedoPack"))
            {
                RemoveFromGame();
            }
        }