Ejemplo n.º 1
0
 public void BodyPartTrigger(Collider other)
 {
     if (!_isGameOver)
     {
         IPlayerContact contact = new PlayerContact();
         contact.OnContactAction(other.gameObject, this);
     }
 }
Ejemplo n.º 2
0
 public void BodyPartCollision(Collision collision)
 {
     if (!_isGameOver)
     {
         IPlayerContact contact = new PlayerContact();
         contact.OnContactAction(collision.gameObject, this);
     }
 }
Ejemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     player     = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerContact>();
     m_Renderer = GetComponent <SpriteRenderer>();
 }
    public static void PlayerAABB(CubeBehaviour a, PlayerBehaviour b)
    {
        PlayerContact contactB = new PlayerContact(b);

        if ((a.min.x <= b.max.x && a.max.x >= b.min.x) &&
            (a.min.y <= b.max.y && a.max.y >= b.min.y) &&
            (a.min.z <= b.max.z && a.max.z >= b.min.z))
        {
            // determine the distances between the contact extents
            float[] distances =
            {
                (b.max.x - a.min.x),
                (a.max.x - b.min.x),
                (b.max.y - a.min.y),
                (a.max.y - b.min.y),
                (b.max.z - a.min.z),
                (a.max.z - b.min.z)
            };

            float   penetration = float.MaxValue;
            Vector3 face        = Vector3.zero;

            // check each face to see if it is the one that connected
            for (int i = 0; i < 6; i++)
            {
                if (distances[i] < penetration)
                {
                    // determine the penetration distance
                    penetration = distances[i];
                    face        = faces[i];
                }
            }

            // set the contact properties
            contactB.face        = face;
            contactB.penetration = penetration;


            // check if contact does not exist
            if (!a.playerContacts.Contains(contactB))
            {
                // remove any contact that matches the name but not other parameters
                for (int i = a.playerContacts.Count - 1; i > -1; i--)
                {
                    if (a.playerContacts[i].player.name.Equals(contactB.player.name))
                    {
                        a.playerContacts.RemoveAt(i);
                    }
                }

                if (contactB.face == Vector3.down)
                {
                    a.gameObject.GetComponent <RigidBody3D>().Stop();
                    a.isGrounded = true;
                }


                // add the new contact
                a.playerContacts.Add(contactB);
                a.isColliding = true;
                print("Is Colliding");

                a.gameObject.GetComponent <RigidBody3D>().velocity = b.body.velocity;
            }
        }
        else
        {
            if (a.playerContacts.Exists(x => x.player.gameObject.name == b.gameObject.name))
            {
                a.playerContacts.Remove(a.playerContacts.Find(x => x.player.gameObject.name.Equals(b.gameObject.name)));
                a.isColliding = false;

                if (a.gameObject.GetComponent <RigidBody3D>().bodyType == BodyType.DYNAMIC)
                {
                    a.gameObject.GetComponent <RigidBody3D>().isFalling = true;
                    a.isGrounded = false;
                }
            }
        }
    }