Example #1
0
        private void end_with_reflection(Collision collision, ColoredBody body_hit)
        {
            var bullet_velocity = movable.Velocity;
            var body_velocity   = body_hit.Movable.Velocity;

            if (!is_reflected)
            {                            // To avoid multiple reflective collisions
                is_reflected = true;
                play_impact_animation(); // TODO: replace by another impact?

                // Now for the rest of the lifetime, we just go in another direction\
                var body_influence_ratio = 2f; // The body movement influences to the reflected direction
                var impact_direction     = (bullet_velocity - body_velocity * body_influence_ratio).normalized;
                transform.forward = Vector3.Reflect(impact_direction, collision.contacts[0].normal);

                // As soon as the bullet is reflected, it can hit anybody matching it!
                clan_who_owns = body_hit.clan;
            }

            // Push the bullet againt the shield
            var min_bullet_push = 1f; // Minimum distance the bullet will be pushed (to be safer from glitches)
            var translation     = transform.forward * Mathf.Max(min_bullet_push, -collision.contacts[0].separation + body_hit.Movable.LastMove.magnitude + movable.LastMove.magnitude);

            if (Mathf.Abs(translation.z) >= 0.1f)
            {
                Debug.LogError("WRONG Z REFLECTION");
            }
            transform.Translate(translation, Space.World);
        }
 private void OnBulletAbsorved(Bullet bullet, ColoredBody body_hit)
 {
     if (bullet.is_player_responsability())
     {
         shot_sequence = 0;
         UpdateDisplay();
     }
 }
Example #3
0
 void Start()
 {
     movable = GetComponentInParent <Movable>();
     my_body = GetComponent <ColoredBody>();
     if (my_body == null)
     {
         Debug.LogError("Bullet objects must have a ColoredBody component!");
     }
 }
 void OnCollisionEnter(Collision collision)
 {
     //Debug.Log("OnCollisionEnter!");
     //Checks the ColoredBody component of anything colliding with the core, and calls on_hit()
     if (clan == Clan.player &&
         gameObject.tag != Bullet.TAG &&
         collision.collider.gameObject.tag != Bullet.TAG)
     {
         ColoredBody otherBody = collision.collider.GetComponentInParent <ColoredBody>();
         if (otherBody != null)
         {
             if (otherBody.clan == Clan.enemy)
             {
                 on_hit();
             }
         }
     }
 }
Example #5
0
        public void on_hit(ColoredBody body_part_hit) // TODO: add the position of the hit point
        {
            //Debug.Log("on_hit!");

            if (!is_alive_in_screen())
            {
                return;
            }

            --hit_points;
            if (hit_points <= 0)
            {
                //Debug.Log("on_hit: die!");
                die();
            }
            else
            {
                HitFX(body_part_hit.transform);
            }
        }